diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-11-02 12:15:40 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-11-02 14:00:29 +0100 |
commit | 50ba4ffdf48461d38f4dd2137a0fbbc916c9eb0a (patch) | |
tree | 6caac8e7a67d27f0a9025523ec6e6a418196740a /tests/auto/qml/qqmllanguage | |
parent | e826636a0bebd0d73e6c17038b24ee2a42d92ead (diff) |
QML: Allow singleton types to be extended
It seems we never stated that singletons can not be extended in our
documentation. Therefore this is technically a bug fix and doesn't need
separate documentation.
Change-Id: I7877289bd5a52ecf709f80ba1975137981ec65f0
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmllanguage')
-rw-r--r-- | tests/auto/qml/qqmllanguage/testtypes.h | 24 | ||||
-rw-r--r-- | tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 23 |
2 files changed, 47 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmllanguage/testtypes.h b/tests/auto/qml/qqmllanguage/testtypes.h index cdcc5faed8..003e9d06ad 100644 --- a/tests/auto/qml/qqmllanguage/testtypes.h +++ b/tests/auto/qml/qqmllanguage/testtypes.h @@ -1583,6 +1583,30 @@ private: FactorySingleton() = default; }; +class ExtendedSingleton : public QObject { + Q_OBJECT + QML_ELEMENT + QML_SINGLETON + QML_EXTENDED(Extension) + + Q_PROPERTY(int foo READ foo CONSTANT) +public: + + int foo() const { return 315; } +}; + +class NamespaceExtendedSingleton : public QObject { + Q_OBJECT + QML_ELEMENT + QML_SINGLETON + QML_EXTENDED_NAMESPACE(ExtensionNamespace) + + Q_PROPERTY(int foo READ foo CONSTANT) +public: + + int foo() const { return 316; } +}; + void registerTypes(); #endif // TESTTYPES_H diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index 40a2ee887a..9a9f13ee0a 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -342,6 +342,7 @@ private slots: void registerValueTypes(); void extendedNamespace(); void factorySingleton(); + void extendedSingleton(); private: QQmlEngine engine; @@ -6065,6 +6066,28 @@ void tst_qqmllanguage::factorySingleton() QCOMPARE(obj->property("mine").toInt(), 314); } +void tst_qqmllanguage::extendedSingleton() +{ + QQmlEngine engine; + QQmlComponent c(&engine); + c.setData("import StaticTest\n" + "import QtQml\n" + "QtObject {\n" + " property int a: ExtendedSingleton.foo\n" + " property int b: NamespaceExtendedSingleton.foo\n" + " property int c: ExtendedSingleton.extension\n" + " property int d: NamespaceExtendedSingleton.Bar\n" + "}", QUrl()); + QVERIFY2(c.isReady(), qPrintable(c.errorString())); + QScopedPointer<QObject> obj(c.create()); + QVERIFY(!obj.isNull()); + + QCOMPARE(obj->property("a").toInt(), 315); + QCOMPARE(obj->property("b").toInt(), 316); + QCOMPARE(obj->property("c").toInt(), 42); + QCOMPARE(obj->property("d").toInt(), 9); +} + QTEST_MAIN(tst_qqmllanguage) #include "tst_qqmllanguage.moc" |