I want to understand the following question:
How can I store the previous value of a property in the declarative QML language?
The task is to memorize property value to another property before it change. The problem is that the existing signal mechanism onPropertyNameChanged(). This mechanism emits a signal about the property change after its modification. And in this handler it is impossible to get the previous value of the property for memorize it.
It is desirable to see code examples.
Interesting question. The only way I see is a bit stupid:
Item {
id: item
property int prev: 0
property int temp: value
property int value: 0
onValueChanged: {
prev = temp;
temp = value;
console.log("prev=" + prev);
console.log("value=" + value)
console.log("---------------");
}
Timer {
interval: 1000
repeat: true
running: true
onTriggered: {
item.value = Math.round(Math.random() * 1000);
}
}
}
why not create the buffer property yourself? eg)
property int value: 0
property int prevValue:
onValueChanged: {
... logic to deal with value change
... if you are trying to diff with prevValue, make sure check if prevValue is not undefined (first time Value changes)
prevValue = value;
}
if you are dealing with custom type "var" then you can try:
onValueChanged: {
prevValue = JSON.parse(JSON.stringify(value));
}
prevValue = JSON.parse(JSON.stringify(value));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With