diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-01-14 17:40:50 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-01-15 10:18:36 +0100 |
commit | c5a8dc153b3d3218360184837b098ba09018d982 (patch) | |
tree | ab80963e58c4593705cb6a67e441433509029079 /tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | |
parent | a07251df7c1e6158cb323e60cb08e687ead15b19 (diff) |
Allow overriding type registrations
Previously if the same revision of the same type was registered multiple
times, the first registration would dominate. Now, the last one does.
[ChangeLog] If you register the same revision of the same type multiple
times, the last registration is the one QML will use. This allows you to
override qmlRegisterSingleton*() calls, for example in order to register
a singleton instance for a type tagged with QML_SINGLETON.
Task-number: QTBUG-79331
Change-Id: I32a2acabc89af6faa89d8ccb6380a473bc8b8ddd
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp')
-rw-r--r-- | tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index fca398d7b2..7b4662a5cd 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -310,6 +310,7 @@ private slots: void selfReferencingSingleton(); void listContainingDeletedObject(); + void overrideSingleton(); private: QQmlEngine engine; @@ -5375,6 +5376,29 @@ void tst_qqmllanguage::listContainingDeletedObject() } +void tst_qqmllanguage::overrideSingleton() +{ + auto check = [](const QString &name) { + const QByteArray testQml = "import Test 1.0\n" + "import QtQml 2.0\n" + "QtObject { objectName: BareSingleton.objectName }"; + QQmlEngine engine; + QQmlComponent component(&engine, nullptr); + component.setData(testQml, QUrl()); + QVERIFY(component.isReady()); + QScopedPointer<QObject> obj(component.create()); + QCOMPARE(obj->objectName(), name); + }; + + check("statically registered"); + + BareSingleton singleton; + singleton.setObjectName("dynamically registered"); + qmlRegisterSingletonInstance("Test", 1, 0, "BareSingleton", &singleton); + + check("dynamically registered"); +} + QTEST_MAIN(tst_qqmllanguage) #include "tst_qqmllanguage.moc" |