diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2011-08-03 11:01:52 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-08-03 03:42:01 +0200 |
commit | 5084c274aac111db3f5f0c38258aa06aa9448bda (patch) | |
tree | 735d55289177451d08a8ff375b0f2f9cebf1883b /src | |
parent | 73aa113181fa2295729d24317c187661f740b898 (diff) |
Prevent Binding from crashing when its target object is deleted.
Task-number: QTBUG-20692
Change-Id: Ia9a3d532c45baf01b8c20c7aac9ef373942a75d8
Reviewed-on: http://codereview.qt.nokia.com/2531
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/util/qdeclarativebind.cpp | 21 | ||||
-rw-r--r-- | src/qtquick1/util/qdeclarativebind.cpp | 3 |
2 files changed, 16 insertions, 8 deletions
diff --git a/src/declarative/util/qdeclarativebind.cpp b/src/declarative/util/qdeclarativebind.cpp index fa463ebef8..320bca853a 100644 --- a/src/declarative/util/qdeclarativebind.cpp +++ b/src/declarative/util/qdeclarativebind.cpp @@ -44,6 +44,7 @@ #include "private/qdeclarativenullablevalue_p_p.h" #include "private/qdeclarativeproperty_p.h" #include "private/qdeclarativebinding_p.h" +#include "private/qdeclarativeguard_p.h" #include <qdeclarativeengine.h> #include <qdeclarativecontext.h> @@ -67,7 +68,7 @@ public: QDeclarativeNullableValue<bool> when; bool componentComplete; - QObject *obj; + QDeclarativeGuard<QObject> obj; QString propName; QDeclarativeNullableValue<QVariant> value; QDeclarativeProperty prop; @@ -196,9 +197,12 @@ QObject *QDeclarativeBind::object() void QDeclarativeBind::setObject(QObject *obj) { Q_D(QDeclarativeBind); - if (d->obj && d->obj != obj) { - qmlInfo(this) << tr("Cannot change the object assigned to a Binding."); - return; + if (d->obj && d->when.isValid() && d->when) { + /* if we switch the object at runtime, we need to restore the + previous binding on the old object before continuing */ + d->when = false; + eval(); + d->when = true; } d->obj = obj; if (d->componentComplete) @@ -220,9 +224,12 @@ QString QDeclarativeBind::property() const void QDeclarativeBind::setProperty(const QString &p) { Q_D(QDeclarativeBind); - if (!d->propName.isEmpty() && d->propName != p) { - qmlInfo(this) << tr("Cannot change the property assigned to a Binding."); - return; + if (!d->propName.isEmpty() && d->when.isValid() && d->when) { + /* if we switch the property name at runtime, we need to restore the + previous binding on the old object before continuing */ + d->when = false; + eval(); + d->when = true; } d->propName = p; if (d->componentComplete) diff --git a/src/qtquick1/util/qdeclarativebind.cpp b/src/qtquick1/util/qdeclarativebind.cpp index 50514234a3..7afe848448 100644 --- a/src/qtquick1/util/qdeclarativebind.cpp +++ b/src/qtquick1/util/qdeclarativebind.cpp @@ -42,6 +42,7 @@ #include "QtQuick1/private/qdeclarativebind_p.h" #include "QtDeclarative/private/qdeclarativenullablevalue_p_p.h" +#include "QtDeclarative/private/qdeclarativeguard_p.h" #include <QtDeclarative/qdeclarativeengine.h> #include <QtDeclarative/qdeclarativecontext.h> @@ -65,7 +66,7 @@ public: bool when : 1; bool componentComplete : 1; - QObject *obj; + QDeclarativeGuard<QObject> obj; QString prop; QDeclarativeNullableValue<QVariant> value; }; |