<?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[TreeView and problem with dataChanged]]></title><description><![CDATA[<p dir="auto">Hello,<br />
I implemented a treeview in QML and i have a problem with dataChanged. It does not update the tree at all. I used "layoutChanged" and it works then, but that's kind of overkill as it reads again all data.</p>
<p dir="auto">I can see that that after i call dataChanged, the "parent" method is called for the item i want to update. No other methods are called.</p>
<p dir="auto">I have a Root structure which contains all the items. Root iself is not shown in the tree. As the item i want to update is in Root, the parent method returns empty QModelIndex. I tried to return Root with index  0 but it did not help.</p>
<p dir="auto">The problem is also visible even if Root is not the parent but another item.</p>
<pre><code>QModelIndex TreeViewModel::parent(const QModelIndex &amp;index) const
{
    qDebug() &lt;&lt; "parent called";
    QModelIndex modelIndex;

    if (index.isValid())
    {
        FileData* item = static_cast&lt;FileData*&gt;(index.internalPointer());
        qDebug() &lt;&lt; "parent called for: " &lt;&lt; item-&gt;filename;
        if (item-&gt;parent &amp;&amp; item-&gt;parent != rootItem)
        {
            qDebug() &lt;&lt; "parent: " &lt;&lt; item-&gt;parent-&gt;filename &lt;&lt; " - " &lt;&lt;item-&gt;parent-&gt;index;
            modelIndex = createIndex(item-&gt;parent-&gt;index, 0, item-&gt;parent);
        }
    }

    return modelIndex;
}

void TreeViewModel::updateData(FileData *item)
{
    //emit layoutAboutToBeChanged();
    qDebug() &lt;&lt; "updateData called";
    QModelIndex index = createIndex(item-&gt;index, 0, item);
    emit dataChanged(index, index, QList&lt;int&gt;({DownloadProgressRole, IsDownloadedRole}));
    //emit layoutChanged();
}
</code></pre>
<p dir="auto">In the QML file, inside TreeView i put<br />
rootIndex: manager.modelIndex</p>
<p dir="auto">which returns the Root item.</p>
<p dir="auto">Any idea what could be wrong?</p>
]]></description><link>https://forum.qt.io/topic/152608/treeview-and-problem-with-datachanged</link><generator>RSS for Node</generator><lastBuildDate>Thu, 24 Sep 2026 19:52:06 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/152608.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 04 Dec 2023 17:49:48 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to TreeView and problem with dataChanged on Thu, 07 Dec 2023 15:46:57 GMT]]></title><description><![CDATA[<p dir="auto">Ok, i found the issue.<br />
Turned out that in the updateData function the item-&gt;index returned wrong index :)</p>
]]></description><link>https://forum.qt.io/post/782176</link><guid isPermaLink="true">https://forum.qt.io/post/782176</guid><dc:creator><![CDATA[Chilli0]]></dc:creator><pubDate>Thu, 07 Dec 2023 15:46:57 GMT</pubDate></item></channel></rss>