简体   繁体   中英

QML: programmatically update binding

有没有一种方法可以以编程方式更新(即重新评估)属性的当前绑定(而无需将其设置为其他值并进行重置)?

If your binding looks something like this:

foo: bar

change it to this:

foo: { baz; bar }

where baz is something that changes often enough to cause foo to be re-evaluated when you need it to, which implies that baz would be related. Similar hacks have been done here , for example.

I would recommend fixing the issue properly by not relying on the order of evaluation.

You can do (hack that should be avoided if possible):

value: foo, bindedValue

or

value: (foo && !foo) || bindedValue

value will be completely reevaluated when calling the following function reevaluateValue() :

property bool foo: false

function reevaluateValue() {
    foo = !foo
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM