diff options
author | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2015-08-16 15:26:40 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2015-08-24 08:12:47 +0000 |
commit | c907eb1b5bfc22ffcee1cc37ecfa762d7a3edd0a (patch) | |
tree | b35cdebde92a7a8e32a6b62e94fa722142227131 /tests | |
parent | 45ea8df187d5dbe2776d793752d1eb3bf34b8fb3 (diff) |
Fix use of function expressions with signal handlers
Writing
onClicked: function(mouseEvent) { ... }
would get silently "accepted" by the engine, but it wouldn't do anything. We
basically wrapped it in a new function, so that it became
onClicked: function(mouse){ function(mouseEvent() {} }
which is a noop. With older versions this used to produce a syntax error.
However the better fix is to simply support this kind of assignment for more
expressive signal handlers, because now the names of the signal parameters can
be explicitly named (with names of your choice).
Change-Id: I96369f8805fab97509784222f614ee17cf681aba
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Reviewed-by: Michael Brasser <michael.brasser@live.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qml/qqmllanguage/data/assignSignalFunctionExpression.qml | 5 | ||||
-rw-r--r-- | tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 12 |
2 files changed, 17 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmllanguage/data/assignSignalFunctionExpression.qml b/tests/auto/qml/qqmllanguage/data/assignSignalFunctionExpression.qml new file mode 100644 index 0000000000..bf8f8556c1 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/assignSignalFunctionExpression.qml @@ -0,0 +1,5 @@ +import Test 1.0 +MyQmlObject { + onBasicSignal: function() { basicSlot() } + onBasicParameterizedSignal: function(param) { basicSlotWithArgs(param) } +} diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index 152b7510d2..97501118dd 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -117,6 +117,7 @@ private slots: void idProperty(); void autoNotifyConnection(); void assignSignal(); + void assignSignalFunctionExpression(); void overrideSignal_data(); void overrideSignal(); void dynamicProperties(); @@ -1263,6 +1264,17 @@ void tst_qqmllanguage::assignSignal() emit object->basicParameterizedSignal(9); } +void tst_qqmllanguage::assignSignalFunctionExpression() +{ + QQmlComponent component(&engine, testFileUrl("assignSignalFunctionExpression.qml")); + VERIFY_ERRORS(0); + MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create()); + QVERIFY(object != 0); + QTest::ignoreMessage(QtWarningMsg, "MyQmlObject::basicSlot"); + emit object->basicSignal(); + QTest::ignoreMessage(QtWarningMsg, "MyQmlObject::basicSlotWithArgs(9)"); + emit object->basicParameterizedSignal(9); +} void tst_qqmllanguage::overrideSignal_data() { |