Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.1.1, 5.6.1
-
f38e071f5b353cbf9ce6c6c104bd82099ae0aa14
Description
The Binding type only restores a property's original value if was set to an expression, and not a constant value.
Take the following example:
import QtQuick 2.0 Rectangle { id: root property int count property bool enableBinding: true width: 200; height: 200 color: "blue" // Doesn't work, this color won't be restored when enableBinding=true //color: true ? "blue" : "blue" // Works, this color will be restored when enableBinding=true Timer { interval: 800 running: true repeat: true onTriggered: root.count += 1 } Binding { id: binding target: root property: "color" value: count % 2 ? "green" : "yellow" when: enableBinding } focus: true Keys.onSpacePressed: { enableBinding = !enableBinding } }
The Rectangle's color is initially set to blue, but the Binding object causes the Rectangle's color to alternate between green and yellow.
When enableBinding=false, this binding is disabled, and the original blue color should be restored. However, this only happens if the initial color property value was set as an expression (e.g. "if (1) "blue") and not if it was set as a constant (e.g. "blue").
This makes the Binding type unusable in the case where a library component needs to temporarily modify a provided object, as there is no guarantee that the object's original property value will be restored.
Attachments
Issue Links
- is duplicated by
-
QTBUG-56272 QML Binding {} Type doesn't restore previously set value in conditional case
- Closed
- relates to
-
QTBUG-15928 Binding element when used internally to a component overrides external bindings
- Closed
-
QTBUG-78566 Binding QML Type does not warn on qt.qml.binding.removal
- Closed