summaryrefslogtreecommitdiffstats
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-10 13:11:46 +0100
commite887f25dd6c4c9630a7367c3a2ed95a284191843 (patch)
tree9b72734c19a36452d66efa206195d4e29e761c1b
parentad5e35dbb98765d8015a4b0d80af02ec6a1c2e7c (diff)
Fix QJSValue string parameters used in signals
Pick-to: 6.1 6.0 5.15 Fixes: QTBUG-86482 Change-Id: If938fad22f51b08fe3cb20b94634efe46a1eed47 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
-rw-r--r--src/qml/qml/qqmlboundsignal.cpp2
-rw-r--r--tests/auto/qml/qqmllanguage/testtypes.h11
-rw-r--r--tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp21
3 files changed, 33 insertions, 1 deletions
diff --git a/src/qml/qml/qqmlboundsignal.cpp b/src/qml/qml/qqmlboundsignal.cpp
index 5fd06da4bb..8fceb94f45 100644
--- a/src/qml/qml/qqmlboundsignal.cpp
+++ b/src/qml/qml/qqmlboundsignal.cpp
@@ -202,7 +202,7 @@ void QQmlBoundSignalExpression::evaluate(void **a)
// for several cases (such as QVariant type and QObject-derived types)
//args[ii] = engine->metaTypeToJS(type, a[ii + 1]);
if (type == qMetaTypeId<QJSValue>()) {
- jsCall->args[ii] = QJSValuePrivate::asReturnedValue(reinterpret_cast<QJSValue *>(a[ii + 1]));
+ jsCall->args[ii] = QJSValuePrivate::convertToReturnedValue(v4, *reinterpret_cast<QJSValue *>(a[ii + 1]));
} else if (type == QMetaType::QVariant) {
jsCall->args[ii] = scope.engine->fromVariant(*((QVariant *)a[ii + 1]));
} else if (type == QMetaType::Int) {
diff --git a/tests/auto/qml/qqmllanguage/testtypes.h b/tests/auto/qml/qqmllanguage/testtypes.h
index 74cd608471..73da55ef3f 100644
--- a/tests/auto/qml/qqmllanguage/testtypes.h
+++ b/tests/auto/qml/qqmllanguage/testtypes.h
@@ -1703,6 +1703,17 @@ public:
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 401203401e..f174b78e9b 100644
--- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
+++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
@@ -346,6 +346,7 @@ private slots:
void factorySingleton();
void extendedSingleton();
void qtbug_85932();
+ void qtbug_86482();
void multiExtension();
void invalidInlineComponent();
@@ -6168,6 +6169,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"