如何在更改之前获取先前的属性值?(在 QML 中) [英] How to get previous property value before it changed? (in QML)

查看:44
本文介绍了如何在更改之前获取先前的属性值?(在 QML 中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解以下问题:

如何在声明式中存储属性的先前值QML 语言?

How can I store the previous value of a property in the declarative QML language?

任务是在更改之前将属性值记忆到另一个属性.问题在于现有信号机制onPropertyNameChanged().此机制在修改后发出有关属性更改的信号.并且在这个处理程序中不可能获得该属性的先前值来记忆它.

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.

最好看代码示例.

推荐答案

有趣的问题.我看到的唯一方式有点愚蠢:

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);
        }
    }
}

这篇关于如何在更改之前获取先前的属性值?(在 QML 中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆