From 70004585f89f325f398c556d101bfa1833d87b53 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Fri, 6 Dec 2013 10:51:42 +0100 Subject: Change C++ parameter type used for var parameters in QML declared signals "signal someSignal(var foo)" mapped to foo being of type QVariant. Unfortunately that is a "lossy" type and it cannot represent all JavaScript values, including for example function closures (as reported in the JIRA bug). Instead we should use QJSValue. It is an important behavioural change because it affects the presumably rare case of somebody declaring a signal in QML with such a parameter and connect to it from C++ (or trying to emit it) - in that situation the code needs to be changed. Task-number: QTBUG-35171 Change-Id: I4fb4a18b407e4ea6c28a3a297fc6f76edb76d734 Reviewed-by: Lars Knoll --- tests/auto/qml/qqmlecmascript/data/signalHandlers.qml | 11 +++++++++++ tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 3 +++ tests/auto/qml/qqmlmetaobject/tst_qqmlmetaobject.cpp | 6 +++--- 3 files changed, 17 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/auto/qml/qqmlecmascript/data/signalHandlers.qml b/tests/auto/qml/qqmlecmascript/data/signalHandlers.qml index 7e85312692..cd68fb9b82 100644 --- a/tests/auto/qml/qqmlecmascript/data/signalHandlers.qml +++ b/tests/auto/qml/qqmlecmascript/data/signalHandlers.qml @@ -91,4 +91,15 @@ QtObject { testObjectWithAliasHandler.count++ return testObjectWithAliasHandler.testSuccess } + + signal signalWithClosureArgument(var f) + onSignalWithClosureArgument: f() + + function testSignalWithClosureArgument() { + var testSuccess = false + signalWithClosureArgument(function() { + testSuccess = true + }) + return testSuccess + } } diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index 7b89709923..d06266a360 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -6068,6 +6068,9 @@ void tst_qqmlecmascript::signalHandlers() QMetaObject::invokeMethod(o, "testAliasSignalHandler", Q_RETURN_ARG(QVariant, result)); QCOMPARE(result.toBool(), true); + QMetaObject::invokeMethod(o, "testSignalWithClosureArgument", Q_RETURN_ARG(QVariant, result)); + QCOMPARE(result.toBool(), true); + delete o; } diff --git a/tests/auto/qml/qqmlmetaobject/tst_qqmlmetaobject.cpp b/tests/auto/qml/qqmlmetaobject/tst_qqmlmetaobject.cpp index b1f83fcd6c..b0c7c5e81a 100644 --- a/tests/auto/qml/qqmlmetaobject/tst_qqmlmetaobject.cpp +++ b/tests/auto/qml/qqmlmetaobject/tst_qqmlmetaobject.cpp @@ -329,11 +329,11 @@ void tst_QQmlMetaObject::method_data() << (QList() << "int" << "bool" << "double") << (QList() << "foo" << "bar" << "baz"); QTest::newRow("testSignal(variant foo, var bar)") << "signal.4.qml" - << "testSignal(QVariant,QVariant)" + << "testSignal(QVariant,QJSValue)" << QMetaMethod::Signal << int(QMetaType::Void) << "void" - << (QList() << QMetaType::QVariant << QMetaType::QVariant) - << (QList() << "QVariant" << "QVariant") + << (QList() << QMetaType::QVariant << qMetaTypeId()) + << (QList() << "QVariant" << "QJSValue") << (QList() << "foo" << "bar"); QTest::newRow("testSignal(color foo, date bar, url baz)") << "signal.5.qml" << "testSignal(QColor,QDateTime,QUrl)" -- cgit v1.2.3