<?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[Do i have to check QModelIndex::isValid() in overriden methods of QAbstractListModel]]></title><description><![CDATA[<p dir="auto">I'm writing a custom item model implementation - i have a class that inherits from QAbstractListModel and overrides</p>
<ul>
<li><code>Qt::ItemFlags flags( const QModelIndex &amp; index )</code></li>
<li><code>QVariant data( const QModelIndex &amp; index, int role )</code></li>
<li><code>bool setData( const QModelIndex &amp; index, const QVariant &amp; value, int role )</code></li>
<li><code>QMimeData * mimeData( const QModelIndexList &amp; indexes )</code></li>
<li>... and more ...</li>
</ul>
<p dir="auto">In these functions named above, do i have to check if the model indexes are valid, or can i count with the framework always supplying me valid ones? I haven't seen this being specified anywhere in the documentation.</p>
]]></description><link>https://forum.qt.io/topic/161690/do-i-have-to-check-qmodelindex-isvalid-in-overriden-methods-of-qabstractlistmodel</link><generator>RSS for Node</generator><lastBuildDate>Tue, 13 Oct 2026 02:56:35 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/161690.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 06 Apr 2025 09:42:23 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Do i have to check QModelIndex::isValid() in overriden methods of QAbstractListModel on Sun, 06 Apr 2025 11:30:01 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/youda0008">@<bdi>Youda0008</bdi></a><br />
Most code does/should check.  If you look at the base implementations in <code>QAbstractListModel</code> I think you will see they do check <code>isValid()</code>?  Or at least all derived classes?  Since you are overriding them, or doing your own stuff before you call them, I would check.  It's only an <code>if</code>.  Or at least check if compiling for debug?</p>
]]></description><link>https://forum.qt.io/post/824084</link><guid isPermaLink="true">https://forum.qt.io/post/824084</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Sun, 06 Apr 2025 11:30:01 GMT</pubDate></item></channel></rss>