Loop of onChanged
-
Hello,
I have a little problem that I can't solve.
I have a value that I want to update when I press on my control. So far, no problem but this same value can be updated via other controls. So, I get into a loop between my onChanged and my application crashes...
I simplified my problem with the example below.Window { id: root width: 640 height: 480 visible: true property int myValue: 0 onMyValueChanged: { if (myValue >= 5) { switch1.checked = true; } else { switch1.checked = false; } } Slider { id: slider x: 350 y: 212 stepSize: 1 to: 10 value: myValue onValueChanged: myValue = value; } Switch { id: switch1 x: 175 y: 209 text: qsTr("Switch") onCheckedChanged: { if (checked == true) { myValue += 5; } else { myValue -= 5; } } } }
I want to update my value from two different places while keeping the "Controls" that can also drive it updated.
How can I do this?Thank you for your help !
-
Don't create logical loops.
Window { id: root width: 640 height: 480 visible: true property int myValue: 0 Slider { id: slider x: 350 y: 212 stepSize: 1 to: 10 value: myValue onValueChanged: myValue = value; } Switch { id: switch1 x: 175 y: 209 text: qsTr("Switch") checked: myValue >= 5 onClicked: { if(checked){ myValue += 5 }else{ myValue -= 5 } } } }
Honestly though, you should have an indicator and 2 separate buttons to increment and decrement. Not sure what you are trying to do here.