diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-12-12 14:05:14 +0100 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-12-15 14:59:32 +0100 |
commit | 428cfe2ffd54f8ac03b4acf259de58b7d4fa704f (patch) | |
tree | 348e53ec2651cdb1838ace19c5a31353ef2c51d2 /tests/auto/qml | |
parent | 9f7c04985dfe0337cfe8d20ef7605b0a837c199b (diff) |
qqmltypeloader: Allow pluginless qmldir + declarative type registration
Assume an application which uses a QML singleton (so needs qmldir), and
wants to use declarative type registration. This currently breaks
because we find the qmldir, see that there is no plugin to load, and
thus never search for registration functions.
Requiring the creation of a plugin is rather pointless for an
application which doesn't reuse the QML types; so instead enable this
usecase to work. Note that qmldir + imperative registration did always
work, as the imperative registration code did always run.
Change-Id: Iac40020eb97d602d10eb8c4eecac5195ffeabe14
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests/auto/qml')
5 files changed, 34 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmltypeloader/CMakeLists.txt b/tests/auto/qml/qqmltypeloader/CMakeLists.txt index 13a7e49b17..e3d59ee35c 100644 --- a/tests/auto/qml/qqmltypeloader/CMakeLists.txt +++ b/tests/auto/qml/qqmltypeloader/CMakeLists.txt @@ -42,6 +42,14 @@ qt_internal_extend_target(tst_qqmltypeloader CONDITION NOT ANDROID AND NOT IOS QT_QMLTEST_DATADIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}/data\\\" ) +qt_add_resources(tst_qqmltypeloader "typeloader" + PREFIX + "/" + FILES + "declarative/import/for/typeloader/test/qmldir" + "declarative/import/for/typeloader/test/Singleton.qml" +) + set_target_properties(tst_qqmltypeloader PROPERTIES QT_QML_MODULE_VERSION 3.2 QT_QML_MODULE_URI declarative.import.for.typeloader.test diff --git a/tests/auto/qml/qqmltypeloader/data/cppAndQmlDir.qml b/tests/auto/qml/qqmltypeloader/data/cppAndQmlDir.qml new file mode 100644 index 0000000000..9d2ea9650e --- /dev/null +++ b/tests/auto/qml/qqmltypeloader/data/cppAndQmlDir.qml @@ -0,0 +1,7 @@ +import QtQml 2.0 +import declarative.import.for.typeloader.test 3.2 + +DeclarativeTestType { + Component.onCompleted: console.log(Singleton, Singleton.objectName) + objectName: Singleton.objectName +} diff --git a/tests/auto/qml/qqmltypeloader/declarative/import/for/typeloader/test/Singleton.qml b/tests/auto/qml/qqmltypeloader/declarative/import/for/typeloader/test/Singleton.qml new file mode 100644 index 0000000000..ace0d6f438 --- /dev/null +++ b/tests/auto/qml/qqmltypeloader/declarative/import/for/typeloader/test/Singleton.qml @@ -0,0 +1,7 @@ +pragma Singleton + +import QtQml + +QtObject { + objectName: "Singleton" +} diff --git a/tests/auto/qml/qqmltypeloader/declarative/import/for/typeloader/test/qmldir b/tests/auto/qml/qqmltypeloader/declarative/import/for/typeloader/test/qmldir new file mode 100644 index 0000000000..c246d8de30 --- /dev/null +++ b/tests/auto/qml/qqmltypeloader/declarative/import/for/typeloader/test/qmldir @@ -0,0 +1 @@ +singleton Singleton 3.2 Singleton.qml diff --git a/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp index 750f9ff402..be5f44dc90 100644 --- a/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp +++ b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp @@ -64,6 +64,7 @@ private slots: void compositeSingletonCycle(); void declarativeCppType(); void circularDependency(); + void declarativeCppAndQmlDir(); private: void checkSingleton(const QString & dataDirectory); }; @@ -649,6 +650,16 @@ void tst_QQMLTypeLoader::circularDependency() QCOMPARE(component.status(), QQmlComponent::Null); } +void tst_QQMLTypeLoader::declarativeCppAndQmlDir() +{ + QQmlEngine engine; + engine.addImportPath("qrc:/"); + QQmlComponent component(&engine, testFileUrl("cppAndQmlDir.qml")); + QVERIFY2(!component.isError(), qPrintable(component.errorString())); + QScopedPointer<QObject> root(component.create()); + QCOMPARE(root->objectName(), "Singleton"); +} + QTEST_MAIN(tst_QQMLTypeLoader) #include "tst_qqmltypeloader.moc" |