aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2017-10-18 15:50:32 +0200
committerUlf Hermann <ulf.hermann@qt.io>2017-10-19 16:26:14 +0000
commitffca73c79d7733f06416f211d5d544dd037c9532 (patch)
treeb9793da38a53c5bf46ed001a98e49d531232fe3c /tests
parent3b6eeee177b64eebe240d51be0c7bb5f031471d8 (diff)
Tell QQmlImportInstance::resolveType what kind of type we want
In QQmlTypeData::resolveTypes() we know if we're looking at a reference to a composite singleton type, or some other type reference. When we call resolveType() we expect the correct type to be returned, not only based on URL, but also based on its singleton property. QQmlTypeData::resolveType() eventually invokes QQmlImportInstance::resolveType() which will call fetchOrCreateTypeForUrl(), passing a parameter on whether the result should be a composite singleton. When operating on a qmldir component the component itself encodes this. When fetching a type from a local file without qmldir, we currently assume that it isn't a singleton, no matter QQmlTypeData::resolveTypes() has determined. This means that actual singletons loaded this way later get refused by the sanity check. In order to fix this, pass the information about the expected singleton property on to QQmlImportInstance. This is done using QQmlType::RegistrationType, which gets another entry for "any type". If the expected type is CompositeSingletonType QQmlTypeData::resolveType() will not create a non-singleton type. If it is any specific other type, it will not create a composite singleton. And if it is AnyRegistrationType, it will behave as it previously did. Change-Id: I6b7e082b63582e0aed946bb3d19077b94c7a45f7 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qqmltypeloader/data/ValueSource.qml7
-rw-r--r--tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp25
2 files changed, 32 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmltypeloader/data/ValueSource.qml b/tests/auto/qml/qqmltypeloader/data/ValueSource.qml
new file mode 100644
index 0000000000..19e6e730c8
--- /dev/null
+++ b/tests/auto/qml/qqmltypeloader/data/ValueSource.qml
@@ -0,0 +1,7 @@
+pragma Singleton
+import QtQuick 2.6
+
+Item {
+ id: valueSource
+ property int something: 10
+}
diff --git a/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp
index 3d3a7ff725..24f3cbc20d 100644
--- a/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp
+++ b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp
@@ -43,6 +43,7 @@ private slots:
void loadComponentSynchronously();
void trimCache();
void trimCache2();
+ void keepSingleton();
};
void tst_QQMLTypeLoader::testLoadComplete()
@@ -120,6 +121,30 @@ void tst_QQMLTypeLoader::trimCache2()
QCOMPARE(loader.isTypeLoaded(testFileUrl("MyComponent2.qml")), false);
}
+static void checkSingleton(const QString &dataDirectory)
+{
+ QQmlEngine engine;
+ engine.addImportPath(dataDirectory);
+ QQmlComponent component(&engine);
+ component.setData("import ClusterDemo 1.0\n"
+ "import QtQuick 2.6\n"
+ "import \"..\"\n"
+ "Item { property int t: ValueSource.something }",
+ QUrl::fromLocalFile(dataDirectory + "/abc/Xyz.qml"));
+ QCOMPARE(component.status(), QQmlComponent::Ready);
+ QScopedPointer<QObject> o(component.create());
+ QVERIFY(o.data());
+ QCOMPARE(o->property("t").toInt(), 10);
+}
+
+void tst_QQMLTypeLoader::keepSingleton()
+{
+ qmlRegisterSingletonType(testFileUrl("ValueSource.qml"), "ClusterDemo", 1, 0, "ValueSource");
+ checkSingleton(dataDirectory());
+ QQmlMetaType::freeUnusedTypesAndCaches();
+ checkSingleton(dataDirectory());
+}
+
QTEST_MAIN(tst_QQMLTypeLoader)
#include "tst_qqmltypeloader.moc"