【发布时间】:2016-04-14 16:42:15
【问题描述】:
我有一个Slider。 value 读取我的持久值,onValueChanged 写入它。但是,将 minimumValue 设置为 1,会在我的 value 初始访问之前调用 onValueChanged。这会导致我的持久值始终被覆盖为 1。
例如
Slider
{
stepSize: 1
minimumValue: 1 // this happens before `value` regarless of order here
maximumValue: 5
value: myPersistentValue
onValueChanged:
{
// gets called *before* myPersistentValue is accessed and overwrites it!
myPersistentValue = value
}
}
有什么方法可以防止这种情况或以某种方式测试准备情况吗?
谢谢。
【问题讨论】:
-
这是一个依赖循环,无效。你必须做点别的,这永远行不通。它只是碰巧起作用,因为 QML 引擎会为您打破依赖循环,作为防止崩溃/冻结 GUI 的最后手段。