<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Controls appear to break bindings when interacted with]]></title><description><![CDATA[<p dir="auto">For example, a basic checkbox:</p>
<pre><code>CheckBox {
    checked: model.value
    onClicked: model.maybe_change_value_maybe_not_depends_on_complex_business_logic();
}
</code></pre>
<p dir="auto">What I expect this means is <code>checked</code> is now <em>bound to</em> <code>model.value</code>, and must <em>never</em> deviate from <code>model.value</code>.  Unfortunately it can. Note my verbosely named function: <em>sometimes</em> the value is changed, but when it isnt the property cannot notify and thus the checkbox becomes desynced.  In this state, <code>checked</code> is <em>observably</em> different from <code>model.value</code>!!  I cannot just do <code>checked = model.value</code> in the slot for <code>onClicked</code> because that breaks the binding completely.  I instead have to do janky stuff like this:</p>
<pre><code>CheckBox {
    property int evil_hacky_hack: 0
    checked: evil_hacky_hack, model.value
    onClicked: {
        model.maybe_change_value_maybe_not_depends_on_complex_business_logic();
        ++evil_hacky_hack // Force a re-evaluate
    }
}
</code></pre>
<p dir="auto">Note that I've observed this happening with other stateful control types, like <code>TextField</code> (with <code>editingFinished</code>).  This leads me to believe that it's a conscious design choice instead of a bug.</p>
<p dir="auto">So I guess my question here: Am I missing a better supported, more scalable way to do this that's applicable to all controls?  Is there a way to make <code>CheckBox</code> (and Qml's controls in general) a pure view for my model data without significant skulduggery?  It's infeasible (and inadvisable, imo) to change my model to notify when a change <em>doesn't</em> happen.</p>
<p dir="auto">Qt 5.9 if it matters; I'm not sure what to search for in changelogs to check for fixes (or how to try this in Qt6).  Also my first post here, lmk if this belongs elsewhere.</p>
]]></description><link>https://forum.qt.io/topic/140504/controls-appear-to-break-bindings-when-interacted-with</link><generator>RSS for Node</generator><lastBuildDate>Sun, 10 May 2026 20:19:44 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/140504.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 03 Nov 2022 23:52:18 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Controls appear to break bindings when interacted with on Fri, 20 Feb 2026 09:31:08 GMT]]></title><description><![CDATA[<p dir="auto">By default, Qt Quick Controls CheckBox updates its checkState when the user interacts with it<br />
(and cycles through states when tristate is enabled). That write breaks a <code>checked: model.value</code><br />
binding, so if your business logic rejects the change and does not update <code>model.value</code>, the UI can<br />
stay desynced.</p>
<p dir="auto">Option 1: handle <code>onToggled</code> and re-establish the binding (and optionally snap back immediately):</p>
<pre><code>CheckBox {
    id: cb
    checked: model.value

    onToggled: function(wanted) {
        model.maybe_change_value_maybe_not_depends_on_complex_business_logic(wanted)

         if (model.value !== wanted) {
            cb.checked = Qt.binding(function() { return model.value })
        }
    }
}
</code></pre>
<p dir="auto">Option 2: override <code>nextCheckState</code> so the control never toggles itself:</p>
<pre><code>CheckBox {
    checked: model.value

    onClicked: model.maybe_change_value_maybe_not_depends_on_complex_business_logic()

    nextCheckState: function() {
        return model.value ? Qt.Checked : Qt.Unchecked
    }
}
</code></pre>
]]></description><link>https://forum.qt.io/post/836447</link><guid isPermaLink="true">https://forum.qt.io/post/836447</guid><dc:creator><![CDATA[J.Hilk]]></dc:creator><pubDate>Fri, 20 Feb 2026 09:31:08 GMT</pubDate></item><item><title><![CDATA[Reply to Controls appear to break bindings when interacted with on Fri, 20 Feb 2026 08:32:02 GMT]]></title><description><![CDATA[<p dir="auto">I strongly agree that this behaviour should be regarded as a bug. If a component (QtQuick.Controls.Button in this case) exposes a mutable property then this implicitly communicates that a client should be able to bind to that property without the binding being overwritten by internal behaviour of the control.</p>
<p dir="auto">(Short of Qt fixing this bug) the more idiomatic fix is probably to reimplement Button yourself, by deriving QtQuick.Templates.Control and ensuring that no public bindings are ever internally overwritten. The problem then is that many other controls in the QtQuick.Controls module expect a QtQuick.Controls.Button in their API and therefore would also need reimplementing to accept your new well behaved button type.. before you know it you're reimplimenting the whole module ! Yeah.. not great.</p>
]]></description><link>https://forum.qt.io/post/836444</link><guid isPermaLink="true">https://forum.qt.io/post/836444</guid><dc:creator><![CDATA[leadbelly]]></dc:creator><pubDate>Fri, 20 Feb 2026 08:32:02 GMT</pubDate></item><item><title><![CDATA[Reply to Controls appear to break bindings when interacted with on Thu, 12 Jan 2023 20:46:53 GMT]]></title><description><![CDATA[<p dir="auto">I dont know if this helps you now, since noone has responded... but the way i solve this (and i've had to do it on multiple ui elements) is as follows:</p>
<ul>
<li>Create custom qml type where the base item is the same as the original (CheckBox in this case)</li>
<li>Add <code>property var checkedBinding</code></li>
<li>Add <code>Component.onCompleted:{if(typeof checkedBinding==='function' checked=Qt.binding(checkedBinding)}</code></li>
<li>Add <code>onClicked:{if(typeof checkedBinding==='function' checked=Qt.binding(checkedBinding)}</code></li>
</ul>
<p dir="auto">Then when using the component, instead of setting <code>checked:model.value</code> you can use <code>checkedBinding:function(){return model.value}</code></p>
<p dir="auto">This is really annoying behavior and i wish qt would fix it. it's not as bad in this simple case, but it can cause a lot of issues when you are doing multiple components put together with custom behavior. The example that bothers me the most is making a DoubleSpinbox item , since the act of changing the binding itself to handle doubles automatically conflicts with using the element itself (even ignoring outside bindings) and will thus automatically unbind itself from the original implementation of the double spin box.</p>
]]></description><link>https://forum.qt.io/post/743655</link><guid isPermaLink="true">https://forum.qt.io/post/743655</guid><dc:creator><![CDATA[IHaber]]></dc:creator><pubDate>Thu, 12 Jan 2023 20:46:53 GMT</pubDate></item></channel></rss>