I trying to understand how bindings works when dynamic objects are used. And don't understand anything.
In code bellow I have "static" bindings:
property bool flag1: cfg_flag1
and create dynamic binding that set flag1 to true
,
then I destroy binding and make sure that it really destroyed (via logs),
after that I trigger initial binding, but looks like binding restoring doesn't work, it prints:
qmlscene /tmp/Test.qml
qml: set flag1 to true
qml: buggon1 cliecked
qml: end of clicked
qml: destroyed
qml: timer trigger
So restoreMode: Binding.RestoreBinding
doesn't restore previous binding or I missed something?
import QtQuick 2.0
import QtQuick.Controls 2.15
Rectangle {
id: rect
width: 100
height: 100
color: "red"
property bool flag1: {
console.log("set flag1 to", cfg_flag1);
return cfg_flag1;
}
property bool cfg_flag1: true
Text {
anchors.centerIn: parent
text: "flag1: " + flag1.toString() + ", cfg_flag1 " + cfg_flag1.toString()
}
Timer {
id: timer
interval: 1000
repeat: false
onTriggered: {
console.log("timer trigger");
cfg_flag1 = false;
}
}
Button {
anchors.top: parent.top
text: "button 1"
onClicked: {
console.log("buggon1 cliecked");
let temp = cmpBinding.createObject(rect, {
"target": rect,
"property": "flag1",
"value": true,
"restoreMode": Binding.RestoreBinding,
});
temp.Component.onDestruction.connect(function() { console.log("destroyed"); });
temp.destroy();
console.log("end of clicked");
timer.start();
}
}
Component {
id: cmpBinding
Binding {
}
}
}
Binding.RestoreBinding
(that is default value) restores binding on the same instance. In your case you delete it and create another instance. – folibisqmlscene
. Not sure what do you mean by providing binding code. – user1244932createObject
call, missed that. – folibis