Qt 5.4/Qml: Prevent binding loop

前端 未结 5 1317
孤街浪徒
孤街浪徒 2021-02-19 04:04

I have a global singleton \"Settings\" which holds application settings. When I try to run the following code I get a QML CheckBox: Binding loop detected for property \"ch

5条回答
  •  失恋的感觉
    2021-02-19 04:31

    If you don't want to make a binding loop - don't make a binding, use a proxy variable, for example. Other simple solution can be to check the value:

    CheckBox {
        checked: Settings.someSetting                         
        onCheckedChanged: {
            if (checked !== Settings.someSetting) {
                Settings.someSetting = checked;
            }
        }
    }
    

提交回复
热议问题