diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2024-02-21 15:01:17 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2024-02-22 22:45:13 +0100 |
commit | 05a9fa44378a96838d56b37eaa59223919d5a721 (patch) | |
tree | f968dfa069010597e5aaab692132c1561b3ecc2b /tests/auto/qml/qqmlimport | |
parent | 406e6054184f87edfbca06cd9ce2a6a7daed9aca (diff) |
QtQml: Load C++-defined types also for the implicit import
If the implicit import does not declare a plugin, that doesn't mean we
don't want to load its C++-defined types.
Pick-to: 6.7
Change-Id: I23427a91f7801cab3a18a5b01c45c520fae7e271
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'tests/auto/qml/qqmlimport')
-rw-r--r-- | tests/auto/qml/qqmlimport/data/noimport/Main.qml | 5 | ||||
-rw-r--r-- | tests/auto/qml/qqmlimport/data/noimport/qmldir | 3 | ||||
-rw-r--r-- | tests/auto/qml/qqmlimport/tst_qqmlimport.cpp | 65 |
3 files changed, 59 insertions, 14 deletions
diff --git a/tests/auto/qml/qqmlimport/data/noimport/Main.qml b/tests/auto/qml/qqmlimport/data/noimport/Main.qml new file mode 100644 index 0000000000..d473b43d7b --- /dev/null +++ b/tests/auto/qml/qqmlimport/data/noimport/Main.qml @@ -0,0 +1,5 @@ +pragma Strict + +TheThing { + width: 640 +} diff --git a/tests/auto/qml/qqmlimport/data/noimport/qmldir b/tests/auto/qml/qqmlimport/data/noimport/qmldir new file mode 100644 index 0000000000..3034edba51 --- /dev/null +++ b/tests/auto/qml/qqmlimport/data/noimport/qmldir @@ -0,0 +1,3 @@ +module noimport +Main 1.0 Main.qml + diff --git a/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp b/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp index f08a8d423a..37a90a74b4 100644 --- a/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp +++ b/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp @@ -1,23 +1,49 @@ // Copyright (C) 2016 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 -#include <QtCore/qscopeguard.h> -#include <QtTest/QtTest> -#include <QQmlApplicationEngine> -#include <QQmlAbstractUrlInterceptor> +#include <private/qmlutils_p.h> +#include <private/qqmlengine_p.h> +#include <private/qqmlimport_p.h> + #include <QtQuick/qquickview.h> #include <QtQuick/qquickitem.h> -#include <private/qqmlimport_p.h> -#include <private/qqmlengine_p.h> -#include <QtQuickTestUtils/private/qmlutils_p.h> -#include <QQmlComponent> + +#include <QtTest/qsignalspy.h> + +#include <QtQml/qqmlabstracturlinterceptor.h> +#include <QtQml/qqmlapplicationengine.h> +#include <QtQml/qqmlcomponent.h> +#include <QtQml/qqmlmoduleregistration.h> + +#include <QtCore/qscopeguard.h> +#include <QtCore/qlibraryinfo.h> + +class TheThing : public QObject +{ + Q_OBJECT + QML_ELEMENT + Q_PROPERTY(int width MEMBER m_width FINAL) + +public: + int m_width = 12; +}; + +void qml_register_types_noimport() +{ + qmlRegisterTypesAndRevisions<TheThing>("noimport", 1); + qmlRegisterModule("noimport", 1, 0); +} class tst_QQmlImport : public QQmlDataTest { Q_OBJECT public: - tst_QQmlImport(); + tst_QQmlImport() + : QQmlDataTest(QT_QMLTEST_DATADIR) + , noimportRegistration("noimport", qml_register_types_noimport) + { + } private slots: void importPathOrder(); @@ -40,6 +66,10 @@ private slots: void implicitWithDependencies(); void qualifiedScriptImport(); void invalidImportUrl(); + void registerTypesFromImplicitImport(); + +private: + QQmlModuleRegistration noimportRegistration; }; void tst_QQmlImport::cleanup() @@ -150,6 +180,18 @@ void tst_QQmlImport::invalidImportUrl() ":2 Cannot resolve URL for import \"file://./MyModuleName\"\n")); } +void tst_QQmlImport::registerTypesFromImplicitImport() +{ + QQmlEngine engine; + QQmlComponent c(&engine, testFileUrl("noimport/Main.qml")); + QVERIFY2(c.isReady(), qPrintable(c.errorString())); + QScopedPointer<QObject> o(c.create()); + QVERIFY(!o.isNull()); + TheThing *t = qobject_cast<TheThing *>(o.data()); + QVERIFY(t); + QCOMPARE(t->m_width, 640); +} + void tst_QQmlImport::testDesignerSupported() { std::unique_ptr<QQuickView> window = std::make_unique<QQuickView>(); @@ -219,11 +261,6 @@ void tst_QQmlImport::uiFormatLoading() QVERIFY(test->rootObjects()[size -1]->property("success").toBool()); } -tst_QQmlImport::tst_QQmlImport() - : QQmlDataTest(QT_QMLTEST_DATADIR) -{ -} - void tst_QQmlImport::importPathOrder() { #ifdef Q_OS_ANDROID |