aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@qt.io>2018-03-19 13:14:13 +0100
committerSimon Hausmann <simon.hausmann@qt.io>2018-03-28 12:26:48 +0000
commiteb4f43a3f69c550213ed0b33cd35786a9a7cbc9f (patch)
tree0292e66b7cde966c9687cdfce62643e81748e3e4 /src/imports
parent59cc1c7d58a0b20b2c079eefd057b93197d84b32 (diff)
Handle function expressions as signal handlers
There are two ways to use function expressions on the right-hand side of bindings: property var somethingPressed somethingPressed: function() { /* ..press something else.. */ } signal buttonPressed onButtonPressed: function() { /* ..handle buttonPress.. */ } In the former case, it declares a property that holds a function. So on initialization, the right-hand side of the binding returns a closure that gets assigned to the property 'somethingPressed'. In the latter case, the signal handler is explicitly marked as a function for clarity. So, the handler should not be returning the closure, but the handler should *be* the closure. In general, it is not possible to detect if the left-hand side is a property or a signal handler when generating QML cache files ahead of time. So for this case, we mark the function as only returning a closure. Then when instantiating the object, we check if it is a signal handler, and if the handler is marked as only returning a closure. If so, we set that closure to be the signal handler. This patch also handles function expressions in SignalTransition and function expressions as signal handlers. Task-number: QTBUG-57043 Task-number: QTBUG-50328 Task-number: QTBUG-50328 (cherry picked from commit 22b13921f8067f8a93164875a4ad59bed85b0400) (cherry picked from commit dc4d6293f9473c0f03c570430d08867d2d01c6e2) (cherry picked from commit 21301c1dbb00f4a2cd991e520423ed039b297ffb) Change-Id: I3008ddd847e30b7d0adef07344a326f84d85f1ba Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/imports')
-rw-r--r--src/imports/statemachine/signaltransition.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/imports/statemachine/signaltransition.cpp b/src/imports/statemachine/signaltransition.cpp
index 0f88ec641b..7057fd0621 100644
--- a/src/imports/statemachine/signaltransition.cpp
+++ b/src/imports/statemachine/signaltransition.cpp
@@ -176,9 +176,10 @@ void SignalTransition::connectTriggered()
QMetaMethod metaMethod = target->metaObject()->method(qobjectSignal->methodIndex());
int signalIndex = QMetaObjectPrivate::signalIndex(metaMethod);
- QQmlBoundSignalExpression *expression = ctxtdata ?
- new QQmlBoundSignalExpression(target, signalIndex,
- ctxtdata, this, m_compilationUnit->runtimeFunctions[binding->value.compiledScriptIndex]) : 0;
+ auto f = m_compilationUnit->runtimeFunctions[binding->value.compiledScriptIndex];
+ QQmlBoundSignalExpression *expression =
+ ctxtdata ? new QQmlBoundSignalExpression(target, signalIndex, ctxtdata, this, f)
+ : nullptr;
if (expression)
expression->setNotifyOnValueChanged(false);
m_signalExpression = expression;