<?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[Asynchronously populating a QAbstractItemModel not working]]></title><description><![CDATA[<p dir="auto">I am implementing an QAbstractItemModel which fetches data asynchronously over a slow connection. From what I read the methods in QAbstractItemModel should return a response immediately, which can be overwritten later. So I built a simple QAbstractItemModel overriding only rowcount and data.</p>
<p dir="auto">My algorithm is:</p>
<p dir="auto">Upon rowCount() called return cached value or 0 if never fetched before<br />
Fetch rowCount from remote slow database<br />
Upon receipt of response issue beginInsertRows and endInsertRows<br />
That works, but the data method is never called. So my 3 items in the view are empty. Why is 'data' not called for each item?</p>
<p dir="auto">...I originally posted this in the QML forum but per suggestion maybe it belongs here instead.</p>
]]></description><link>https://forum.qt.io/topic/127435/asynchronously-populating-a-qabstractitemmodel-not-working</link><generator>RSS for Node</generator><lastBuildDate>Fri, 12 Jun 2026 03:30:43 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/127435.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 09 Jun 2021 23:06:27 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Asynchronously populating a QAbstractItemModel not working on Thu, 10 Jun 2021 19:31:03 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ocgltd">@<bdi>ocgltd</bdi></a><br />
You may not get a good response with just this explanation and no code.  <em>For example</em></p>
<blockquote>
<p dir="auto">simple QAbstractItemModel overriding only rowcount and data</p>
</blockquote>
<p dir="auto">This does not appear to meet the <em>minimum</em> requirements of <strong>Model Subclassing Reference</strong> as per <a href="https://doc.qt.io/qt-5/model-view-programming.html#read-only-access" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-5/model-view-programming.html#read-only-access</a>.</p>
<p dir="auto">I also don't understand <em>when</em> you your <code>rowCount()</code> ceases to just return 0.  But that may be a detail.</p>
<p dir="auto">Your "slow" model also <em>might</em> benefit from implementation of the "fetch more" interface.</p>
<p dir="auto">A lot of people would suggest you <em>test</em> your implementation via <a href="https://doc.qt.io/qt-5/qabstractitemmodeltester.html" target="_blank" rel="noopener noreferrer nofollow ugc">QAbstractItemModelTester Class</a> before you proceed any further.</p>
]]></description><link>https://forum.qt.io/post/664342</link><guid isPermaLink="true">https://forum.qt.io/post/664342</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Thu, 10 Jun 2021 19:31:03 GMT</pubDate></item></channel></rss>