summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaximilian Goldstein <max.goldstein@qt.io>2021-02-09 11:37:45 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-02-10 16:12:09 +0000
commitb2fccf2f2d15c91cf52ca9a2a779eae3004f8b55 (patch)
tree640f75fa78ae04bb2190541d5b127ab52c34a19a
parent16a09446677b196bd763b54dc5e2b46afaf5add5 (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) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-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 77f09a232c..8f4071d9b8 100644
--- a/tests/auto/qml/qqmllanguage/testtypes.h
+++ b/tests/auto/qml/qqmllanguage/testtypes.h
@@ -1700,6 +1700,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 eaee7883f7..46fb83ac9f 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();
@@ -6166,6 +6167,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"