I have a QML document with an int property, a Slider and a Button in it. I want x to always have the same value as Slider.value. Here’s my QML:
Page {
property int x: 1
content: Container {
Slider {
fromValue: 1
toValue: 500
value: x
onValueChanged: {
console.log("Slider value is: "+value);
console.log("x value: "+x);
}
}
Button {
text: "Increment x"
onClicked: {
x=x+10;
}
}
}
}
When I press the Button the slider value is updated AND x is updated. But when I move the slider, the value of x is not updated. Why doesn’t the value of x change when I move the slider?
Because your
xis not bind to theSlider.value. When you bindSlider.valuetox, ifxchange,Slider.valuewill also change BUT ifSlider.valuechange (when you slide it),xvalue will not be change.To solve this you can use the alias type