aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMaximilian Goldstein <max.goldstein@qt.io>2021-01-19 17:54:45 +0100
committerMaximilian Goldstein <max.goldstein@qt.io>2021-01-20 12:07:34 +0100
commitbf573ad295fbc1eee9379bfaafcded293c4b81f4 (patch)
tree330a69b72e7de269753c4563c8d59bac5a533d3d /tests
parente9997bc96911923355af2e1dd081cc039a2b2b8f (diff)
QML_SINGLETON: Handle local create() functions with foreign types
Previously only the foreign type was searched for a create method. Now the wrapping type can also contain it. Change-Id: I05fb9e0c0a54c14530eb9adcae5a44df5c208be3 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qqmllanguage/data/foreignSingleton.qml6
-rw-r--r--tests/auto/qml/qqmllanguage/testtypes.h31
-rw-r--r--tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp11
3 files changed, 48 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmllanguage/data/foreignSingleton.qml b/tests/auto/qml/qqmllanguage/data/foreignSingleton.qml
new file mode 100644
index 0000000000..1649df6a25
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/foreignSingleton.qml
@@ -0,0 +1,6 @@
+import QtQml 2.0
+import StaticTest 1.0
+
+QtObject {
+ property int number: ForeignSingleton.number
+}
diff --git a/tests/auto/qml/qqmllanguage/testtypes.h b/tests/auto/qml/qqmllanguage/testtypes.h
index 003e9d06ad..758b9e2f62 100644
--- a/tests/auto/qml/qqmllanguage/testtypes.h
+++ b/tests/auto/qml/qqmllanguage/testtypes.h
@@ -1607,6 +1607,37 @@ public:
int foo() const { return 316; }
};
+class ForeignSingleton : public QObject {
+ Q_OBJECT
+ Q_PROPERTY(int number READ number WRITE setnumber NOTIFY numberchanged)
+public:
+ ForeignSingleton(QObject *parent = nullptr) : QObject(parent) {};
+ int number() { return m_number; }
+ void setnumber(int number) { m_number = number; }
+ static ForeignSingleton *obtain() { return new ForeignSingleton; }
+signals:
+ void numberchanged();
+private:
+ int m_number = 0;
+};
+
+class WrapperSingleton : public QObject {
+ Q_OBJECT
+ QML_NAMED_ELEMENT(ForeignSingleton)
+ QML_FOREIGN(ForeignSingleton)
+ QML_SINGLETON
+
+public:
+ static ForeignSingleton* create(QQmlEngine *, QJSEngine *) {
+ ForeignSingleton *singleton = ForeignSingleton::obtain();
+ singleton->setnumber(42);
+ return singleton;
+ }
+
+private:
+ WrapperSingleton() = default;
+};
+
void registerTypes();
#endif // TESTTYPES_H
diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
index 4f4ee45f68..454ae59ad3 100644
--- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
+++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
@@ -313,6 +313,7 @@ private slots:
void typeWrapperToVariant();
void extendedForeignTypes();
+ void foreignTypeSingletons();
void inlineComponent();
void inlineComponent_data();
@@ -5496,6 +5497,16 @@ void tst_qqmllanguage::extendedForeignTypes()
QCOMPARE(o->property("foreignExtendedObjectName").toString(), QLatin1String("foreignExtended"));
}
+void tst_qqmllanguage::foreignTypeSingletons() {
+ QQmlEngine engine;
+ QQmlComponent component(&engine, testFileUrl("foreignSingleton.qml"));
+ VERIFY_ERRORS(0);
+ QScopedPointer<QObject> o(component.create());
+ QVERIFY(!o.isNull());
+
+ QCOMPARE(o->property("number").toInt(), 42);
+}
+
void tst_qqmllanguage::selfReference()
{
QQmlEngine engine;