Do not bind it. Because the checkbox is not completely dependent on Setting.someSetting .
When the user clicked the checkbox, CheckBox.checked will be changed on its own. At the same time, property bindings are no longer valid. Settings.someSetting cannot change CheckBox after user click. Therefore, the checked: Settings.someSetting binding is incorrect.
If you want to assign an initial value to the flag when the component is ready, use Component.onCompleted to assign it:
CheckBox { id: someSettingCheckBox Component.onCompleted: checked = Settings.someSetting onCheckedChanged: Settings.someSetting = checked; }
If you are working on a more complex scenario, Setting.someSetting can be changed by other things at runtime, and the state of this field must be changed at the same time. Catch the onSomeSettingChanged signal and explicitly change the flag. Send the value of someSettingCheckBox to Settings only after the program / widget / dialog / xxx is completed.
CheckBox { id: someSettingCheckBox }
mcchu source share