<?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[Updating QML view from C++]]></title><description><![CDATA[<p dir="auto">Quick question.<br />
Suppose that I have view in QML displaying some list model defined on the C++ side.  In the model I provide the roles (e.g. "power" and "active").  That way in QML I can refer to them via their names and I do some bindings in delegate (e.g. some CheckBox's "checked" to "active" and some Text's "text" to "power").</p>
<p dir="auto">Everything works OK when it comes to displaying (view is requesting data for correct roles and so on).</p>
<p dir="auto">When I update model on the C++ side I wanted to mark "dirty" only "power" or only "active", so that QML requests only data for the changed part.  However it seems that when emitting <code>dataChanged()</code> I have to use <code>Qt::DisplayRole</code> (which requests data for all roles - above I mentioned only "power" and "active" but there are more defined by me).  If I emit <code>dataChanged()</code> with my defined roles (enum with <code>PowerRole = Qt::UserRole + 1,...</code>) then view is not updating information.</p>
<p dir="auto">Is there a way to notify QML view that something has changed in the model but in a way that it will request only particular (user defined) role?</p>
<p dir="auto">Best regards<br />
Andrzej</p>
]]></description><link>https://forum.qt.io/topic/83066/updating-qml-view-from-c</link><generator>RSS for Node</generator><lastBuildDate>Thu, 15 Oct 2026 01:21:02 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/83066.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 07 Sep 2017 13:32:10 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Updating QML view from C++ on Sat, 09 Sep 2017 07:09:00 GMT]]></title><description><![CDATA[<p dir="auto">Thank you <a class="plugin-mentions-user plugin-mentions-a" href="/user/dheerendra">@<bdi>dheerendra</bdi></a> and <a class="plugin-mentions-user plugin-mentions-a" href="/user/eeli-k">@<bdi>Eeli-K</bdi></a> for taking look at it (and sorry for not replying earlier).  When I was pasting code here to show you how I do it I actually has found the problem :) - my apologies for the noise.</p>
<p dir="auto">It was how I created vector of roles in <code>dataChanged()</code> (I have not used braces) and was emitting it like:</p>
<pre><code>    emit dataChanged(createIndex(0,0), createIndex(2,0), QVector&lt;int&gt;(PowerRole));
</code></pre>
<p dir="auto">instead of:</p>
<pre><code>    emit dataChanged(createIndex(0,0), createIndex(2,0), QVector&lt;int&gt;({PowerRole}))
</code></pre>
<p dir="auto">I wonder how it ever worked when I used <code>QVector&lt;int&gt;(Qt::DisplayRole)</code> - probably by accident :)</p>
<p dir="auto">Thank you for your time<br />
Best regards<br />
Andrzej</p>
]]></description><link>https://forum.qt.io/post/414474</link><guid isPermaLink="true">https://forum.qt.io/post/414474</guid><dc:creator><![CDATA[AndrzejO]]></dc:creator><pubDate>Sat, 09 Sep 2017 07:09:00 GMT</pubDate></item><item><title><![CDATA[Reply to Updating QML view from C++ on Thu, 07 Sep 2017 14:48:34 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/andrzejo">@<bdi>AndrzejO</bdi></a> Quick counter-question: did you implement roleNames()?</p>
]]></description><link>https://forum.qt.io/post/414127</link><guid isPermaLink="true">https://forum.qt.io/post/414127</guid><dc:creator><![CDATA[Eeli K]]></dc:creator><pubDate>Thu, 07 Sep 2017 14:48:34 GMT</pubDate></item><item><title><![CDATA[Reply to Updating QML view from C++ on Thu, 07 Sep 2017 14:37:48 GMT]]></title><description><![CDATA[<p dir="auto">I have done this &amp; it only updates the requested role. Can you copy your code here ? I will check if any issues.</p>
]]></description><link>https://forum.qt.io/post/414124</link><guid isPermaLink="true">https://forum.qt.io/post/414124</guid><dc:creator><![CDATA[dheerendra]]></dc:creator><pubDate>Thu, 07 Sep 2017 14:37:48 GMT</pubDate></item></channel></rss>