From bdbf6a53c0ab8a7f6ea5586767a6ed818e3d555e Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Fri, 4 May 2018 15:17:29 +0200 Subject: Fix loading of composite singletons from resources Commit f6bbeeb417102c61e8bf23f41e412ed9753a348d began normalizing the resource urls in the type loader, which broke loading of qml singletons from resources, as the normalized url is also used for the "pragma singleton" verification to check that the singleton is in the meta-type registry. If the registration was done with a non-normalized url, the check would fail with a misleading error message. Task-number: QTBUG-68025 Change-Id: I1093ee0cbee884b4a51195c302c8908f748e747e Reviewed-by: Lars Knoll Reviewed-by: Christopher Adams --- tests/auto/qml/qqmlmetatype/qqmlmetatype.pro | 4 ++++ tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp | 14 ++++++++++++++ 2 files changed, 18 insertions(+) (limited to 'tests/auto/qml') diff --git a/tests/auto/qml/qqmlmetatype/qqmlmetatype.pro b/tests/auto/qml/qqmlmetatype/qqmlmetatype.pro index 0d8de91931..345bc59615 100644 --- a/tests/auto/qml/qqmlmetatype/qqmlmetatype.pro +++ b/tests/auto/qml/qqmlmetatype/qqmlmetatype.pro @@ -6,4 +6,8 @@ macx:CONFIG -= app_bundle TESTDATA = data/* include (../../shared/util.pri) +qmlfiles.files = data/CompositeType.qml +qmlfiles.prefix = /tstqqmlmetatype +RESOURCES += qmlfiles + QT += core-private gui-private qml-private testlib diff --git a/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp b/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp index ff3361ff82..1d0d353668 100644 --- a/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp +++ b/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp @@ -62,6 +62,8 @@ private slots: void defaultObject(); void unregisterCustomType(); void unregisterCustomSingletonType(); + + void normalizeUrls(); }; class TestType : public QObject @@ -523,6 +525,18 @@ void tst_qqmlmetatype::unregisterCustomSingletonType() } } +void tst_qqmlmetatype::normalizeUrls() +{ + const QUrl url("qrc:///tstqqmlmetatype/data/CompositeType.qml"); + QVERIFY(!QQmlMetaType::qmlType(url).isValid()); + const auto registrationId = qmlRegisterType(url, "Test", 1, 0, "ResourceCompositeType"); + QVERIFY(QQmlMetaType::qmlType(url, /*includeNonFileImports=*/true).isValid()); + QUrl normalizedURL("qrc:/tstqqmlmetatype/data/CompositeType.qml"); + QVERIFY(QQmlMetaType::qmlType(normalizedURL, /*includeNonFileImports=*/true).isValid()); + qmlUnregisterType(registrationId); + QVERIFY(!QQmlMetaType::qmlType(url, /*includeNonFileImports=*/true).isValid()); +} + QTEST_MAIN(tst_qqmlmetatype) #include "tst_qqmlmetatype.moc" -- cgit v1.2.3