From 9d34246a3a8edcce3e20d4364664185c05f313ad Mon Sep 17 00:00:00 2001
From: Marco Bubke <marco.bubke@nokia.com>
Date: Wed, 21 Apr 2010 17:04:27 +0200
Subject: [PATCH] Resetting the binding for a property before destroying it.

Fixing a crash for resetting a binding in a state

Task-Number: BAUHAUS-624
Reviewed-by: kkoehne
---
 .../qmlpropertychangesnodeinstance.cpp         | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/src/plugins/qmldesigner/core/instances/qmlpropertychangesnodeinstance.cpp b/src/plugins/qmldesigner/core/instances/qmlpropertychangesnodeinstance.cpp
index 8b2579f608a..7199113264a 100644
--- a/src/plugins/qmldesigner/core/instances/qmlpropertychangesnodeinstance.cpp
+++ b/src/plugins/qmldesigner/core/instances/qmlpropertychangesnodeinstance.cpp
@@ -406,14 +406,18 @@ void QmlPropertyChangesObject::setExpression(const QString &name, const QString
         m_qmlActionList.append(createQDeclarativeAction(name));
     }
 
+    QDeclarativeContext *context = QDeclarativeEngine::contextForObject(targetObject());
+    QDeclarativeBinding *binding = 0;
+    QDeclarativeProperty metaProperty(targetObject(), name, context);
+
     QDeclarativeAction &qmlAction = qmlActionForProperty(name);
     if (m_expressionHash.contains(name) && m_expressionHash[name].second) {
-        m_expressionHash[name].second->destroy();
+        if (QDeclarativePropertyPrivate::binding(metaProperty) == m_expressionHash[name].second.data())
+            QDeclarativePropertyPrivate::setBinding(metaProperty, 0,  QDeclarativePropertyPrivate::BypassInterceptor | QDeclarativePropertyPrivate::DontRemoveBinding);
+        m_expressionHash.take(name).second->destroy();
     }
 
-    QDeclarativeContext *context = QDeclarativeEngine::contextForObject(targetObject());
-    QDeclarativeBinding *binding = 0;
-    QDeclarativeProperty metaProperty(targetObject(), name, context);
+
     if (metaProperty.isValid() && metaProperty.isProperty()) {
         binding = new QDeclarativeBinding(expression, targetObject(), context, this);
         binding->setTarget(metaProperty);
@@ -486,8 +490,12 @@ void QmlPropertyChangesObject::resetProperty(const QString &name)
     }
 
     if (m_expressionHash.contains(name)) {
-        if (m_expressionHash[name].second)
+        if (m_expressionHash[name].second) {
+            QDeclarativeProperty metaProperty(targetObject(), name, QDeclarativeEngine::contextForObject(targetObject()));
+            if (metaProperty.isValid() && QDeclarativePropertyPrivate::binding(metaProperty) == m_expressionHash[name].second.data())
+                QDeclarativePropertyPrivate::setBinding(metaProperty, 0,  QDeclarativePropertyPrivate::BypassInterceptor | QDeclarativePropertyPrivate::DontRemoveBinding);
             m_expressionHash[name].second.data()->destroy();
+        }
         m_expressionHash.remove(name);
     }
 
-- 
GitLab