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/declarative/util/qdeclarativebind.cpp | |
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/declarative/util/qdeclarativebind.cpp')
-rw-r--r-- | src/declarative/util/qdeclarativebind.cpp | 21 |
1 files changed, 14 insertions, 7 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) |