aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlproperty.cpp
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2012-04-26 16:12:21 +1000
committerQt by Nokia <qt-info@nokia.com>2012-05-01 06:07:00 +0200
commit462edd23f953af6ce37d1c42400e2cb4443f5a24 (patch)
treeef505e16ad6e7a439a6217da191fdaac6d9eda3c /src/qml/qml/qqmlproperty.cpp
parent7cecad76b6a8beb31c74111b986be0e67bb2e15c (diff)
More robust tracking of signal handler expression ownership.
Reference count the expressions, and improve testing. Change-Id: I810509eae1c7608b367e9ff5f7891a294667a692 Reviewed-by: Chris Adams <christopher.adams@nokia.com>
Diffstat (limited to 'src/qml/qml/qqmlproperty.cpp')
-rw-r--r--src/qml/qml/qqmlproperty.cpp35
1 files changed, 25 insertions, 10 deletions
diff --git a/src/qml/qml/qqmlproperty.cpp b/src/qml/qml/qqmlproperty.cpp
index 002986157f..d791d73cbf 100644
--- a/src/qml/qml/qqmlproperty.cpp
+++ b/src/qml/qml/qqmlproperty.cpp
@@ -943,17 +943,34 @@ QQmlPropertyPrivate::signalExpression(const QQmlProperty &that)
/*!
Set the signal expression associated with this signal property to \a expr.
- Returns the existing signal expression (if any), otherwise 0.
+ Returns the existing signal expression (if any), otherwise null.
- Ownership of \a expr transfers to QML. Ownership of the return value is
- assumed by the caller.
+ A reference to \a expr will be added by QML. Ownership of the return value
+ reference is assumed by the caller.
*/
-QQmlBoundSignalExpression *
+QQmlBoundSignalExpressionPointer
QQmlPropertyPrivate::setSignalExpression(const QQmlProperty &that,
QQmlBoundSignalExpression *expr)
{
+ if (expr)
+ expr->addref();
+ return QQmlPropertyPrivate::takeSignalExpression(that, expr);
+}
+
+/*!
+ Set the signal expression associated with this signal property to \a expr.
+ Returns the existing signal expression (if any), otherwise null.
+
+ Ownership of \a expr transfers to QML. Ownership of the return value
+ reference is assumed by the caller.
+*/
+QQmlBoundSignalExpressionPointer
+QQmlPropertyPrivate::takeSignalExpression(const QQmlProperty &that,
+ QQmlBoundSignalExpression *expr)
+{
if (!(that.type() & QQmlProperty::SignalProperty)) {
- delete expr;
+ if (expr)
+ expr->release();
return 0;
}
@@ -967,15 +984,13 @@ QQmlPropertyPrivate::setSignalExpression(const QQmlProperty &that,
signalHandler = signalHandler->m_nextSignal;
if (signalHandler)
- return signalHandler->setExpression(expr);
+ return signalHandler->takeExpression(expr);
if (expr) {
QQmlBoundSignal *signal = new QQmlBoundSignal(that.d->object, that.method(), that.d->object);
- QQmlBoundSignalExpression *oldExpr = signal->setExpression(expr);
- return oldExpr;
- } else {
- return 0;
+ signal->takeExpression(expr);
}
+ return 0;
}
/*!