我想了解以下问题:
How can I store the previous value of a property in the declarative QML language?
任务是在更改之前将属性值内存到另一个属性。问题在于现有的信号机制 onPropertyNameChanged() .此机制在修改后发出有关属性更改的信号。而在这个处理程序中,不可能获得该属性的先前值来记住它。
最好看代码示例。
最佳答案
有趣的问题。我看到的唯一方法是有点愚蠢:
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);
}
}
}
关于properties - 如何在更改之前获取先前的属性值? (在 QML 中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48442597/