<?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[can&#x27;t read data from stored data with Qt::UserRole and custom QStandardItemModel()]]></title><description><![CDATA[<p dir="auto">Hi all,<br />
I build QTableview and QStandardItemModel as model.  When i store data with<br />
QStandardItem ....itm-&gt;setData(qw,Qt::UserRole);  and after i can reach the data with index....data(Qt::UserRole).toInt(); successfully.<br />
But when i customize QStandardItemModel and reuse "data(const QModelIndex &amp;index, int role) const" i can't reach indexed data. What value should i return in function or what am i missing?</p>
<p dir="auto">I tried as below list code but failed.</p>
<p dir="auto">data(const QModelIndex &amp;index, int role) const<br />
..<br />
if (role == Qt::UserRole)<br />
{<br />
return QVariant(index.data(Qt::UserRole).toInt())<br />
}<br />
or<br />
if (role == Qt::UserRole)<br />
{<br />
return QVariant();<br />
}</p>
]]></description><link>https://forum.qt.io/topic/78356/can-t-read-data-from-stored-data-with-qt-userrole-and-custom-qstandarditemmodel</link><generator>RSS for Node</generator><lastBuildDate>Mon, 13 Apr 2026 20:43:41 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/78356.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 18 Apr 2017 06:04:04 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to can&#x27;t read data from stored data with Qt::UserRole and custom QStandardItemModel() on Tue, 18 Apr 2017 07:21:47 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/vronin">@<bdi>VRonin</bdi></a> thank you very much</p>
]]></description><link>https://forum.qt.io/post/388363</link><guid isPermaLink="true">https://forum.qt.io/post/388363</guid><dc:creator><![CDATA[mete]]></dc:creator><pubDate>Tue, 18 Apr 2017 07:21:47 GMT</pubDate></item><item><title><![CDATA[Reply to can&#x27;t read data from stored data with Qt::UserRole and custom QStandardItemModel() on Tue, 18 Apr 2017 07:17:07 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mete">@<bdi>mete</bdi></a> said in <a href="/post/388350">can't read data from stored data with Qt::UserRole and custom QStandardItemModel()</a>:</p>
<blockquote>
<p dir="auto"><code>return QVariant(index.data(Qt::UserRole).toInt())</code></p>
</blockquote>
<p dir="auto">will just call an infinite recursion and converting a variant to an int and back to a variant has no practical application I can see but anyway...<br />
<code>return QVariant(QStandardItemModel::data(index,Qt::UserRole).toInt())</code></p>
]]></description><link>https://forum.qt.io/post/388361</link><guid isPermaLink="true">https://forum.qt.io/post/388361</guid><dc:creator><![CDATA[VRonin]]></dc:creator><pubDate>Tue, 18 Apr 2017 07:17:07 GMT</pubDate></item></channel></rss>