aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorMaximilian Goldstein <max.goldstein@qt.io>2021-02-09 11:37:45 +0100
committerMaximilian Goldstein <max.goldstein@qt.io>2021-02-11 13:22:46 +0100
commitc48ba63c9001a6965f3ea7e0ddbceacf994f777e (patch)
tree87052be5b48251045ccbd556d080651a62bf894e /tests/auto
parent76aa032bb5554945fe05f6e71b8a8cee7ba73c17 (diff)
Fix QJSValue string parameters used in signals
Fixes: QTBUG-86482 Change-Id: If938fad22f51b08fe3cb20b94634efe46a1eed47 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> (cherry picked from commit e887f25dd6c4c9630a7367c3a2ed95a284191843)
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qml/qqmllanguage/testtypes.h104
-rw-r--r--tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp21
2 files changed, 125 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmllanguage/testtypes.h b/tests/auto/qml/qqmllanguage/testtypes.h
index 003e9d06ad..8f4071d9b8 100644
--- a/tests/auto/qml/qqmllanguage/testtypes.h
+++ b/tests/auto/qml/qqmllanguage/testtypes.h
@@ -1607,6 +1607,110 @@ 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;
+};
+
+class ExtensionA : public QObject
+{
+ Q_OBJECT
+ QML_ANONYMOUS
+ Q_PROPERTY(int a READ a CONSTANT)
+ Q_PROPERTY(int c READ c CONSTANT)
+ Q_PROPERTY(int d READ d CONSTANT)
+ Q_PROPERTY(int f READ f CONSTANT)
+ Q_PROPERTY(int g READ g CONSTANT)
+public:
+ ExtensionA(QObject *parent = nullptr) : QObject(parent) {}
+ int a() const { return 'a'; }
+ int c() const { return 11; }
+ int d() const { return 21; }
+ int f() const { return 31; }
+ int g() const { return 41; }
+};
+
+class ExtensionB : public QObject
+{
+ Q_OBJECT
+ QML_ANONYMOUS
+ Q_PROPERTY(int b READ b CONSTANT)
+ Q_PROPERTY(int c READ c CONSTANT)
+ Q_PROPERTY(int d READ d CONSTANT)
+public:
+ ExtensionB(QObject *parent = nullptr) : QObject(parent) {}
+ int b() const { return 'b'; }
+ int c() const { return 12; }
+ int d() const { return 22; }
+};
+
+class MultiExtensionParent : public QObject
+{
+ Q_OBJECT
+ QML_ANONYMOUS
+ QML_EXTENDED(ExtensionA)
+ Q_PROPERTY(int p READ p CONSTANT)
+ Q_PROPERTY(int c READ c CONSTANT)
+ Q_PROPERTY(int f READ f CONSTANT)
+public:
+ MultiExtensionParent(QObject *parent = nullptr) : QObject(parent) {}
+ int p() const { return 'p'; }
+ int c() const { return 13; }
+ int f() const { return 33; }
+};
+
+class MultiExtension : public MultiExtensionParent
+{
+ Q_OBJECT
+ QML_ELEMENT
+ QML_EXTENDED(ExtensionB)
+ Q_PROPERTY(int e READ e CONSTANT)
+ Q_PROPERTY(int c READ c CONSTANT)
+ Q_PROPERTY(int g READ g CONSTANT)
+public:
+ MultiExtension(QObject *parent = nullptr) : MultiExtensionParent(parent) {}
+ int e() const { return 'e'; }
+ int c() const { return 14; }
+ int g() const { return 44; }
+};
+
+class StringSignaler : public QObject
+{
+ Q_OBJECT
+ QML_ELEMENT
+public:
+ StringSignaler(QObject *parent = nullptr) : QObject(parent) {}
+ Q_INVOKABLE void call() { emit signal(QJSValue("Hello world!")); }
+signals:
+ void signal(QJSValue value);
+};
+
void registerTypes();
#endif // TESTTYPES_H
diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
index bf818b9005..f3b11b4a6b 100644
--- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
+++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
@@ -343,6 +343,7 @@ private slots:
void extendedNamespace();
void factorySingleton();
void extendedSingleton();
+ void qtbug_86482();
void invalidInlineComponent();
@@ -6105,6 +6106,26 @@ void tst_qqmllanguage::invalidInlineComponent()
QVERIFY(c.errorString().contains("\"Window.visibility\" is not available in QtQuick 2.0."));
}
+void tst_qqmllanguage::qtbug_86482()
+{
+ QQmlEngine engine;
+ QQmlComponent component(&engine);
+ component.setData(QByteArray(R"(import QtQml 2.0
+ import StaticTest
+ QtObject {
+ id: root
+ property string result
+ property StringSignaler str: StringSignaler {
+ onSignal: function(value) { root.result = value; }
+ }
+ Component.onCompleted: str.call();
+ })"), QUrl());
+ VERIFY_ERRORS(0);
+ QScopedPointer<QObject> o(component.create());
+ QVERIFY2(component.isReady(), qPrintable(component.errorString()));
+ QCOMPARE(o->property("result").toString(), QStringLiteral("Hello world!"));
+}
+
QTEST_MAIN(tst_qqmllanguage)
#include "tst_qqmllanguage.moc"