<?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[QT QML How to chain QAbstractListModel and QSortFilterProxyModel]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">I'm working on a project where I get a large JSON as input, this JSON can change at any time. Items can be removed, added and changed.</p>
<p dir="auto">I want to to be able to access this data in QML. And I want the QML to be able to sort and filter the data. And I want to do it the right way.</p>
<p dir="auto">I have broken down the input data into a view model in C++, which consists of a number of implementations of QAbstractListModels. As I do not want to expose QLists with elements to QML. And I want to be able to chain those with filters and sorters. So I have implemented a number of QSortFilterProxyModels for that purpose. One of these I want to be able to limit the number of outputs.</p>
<p dir="auto">So I want something like: List -&gt; Some kind of filtering -&gt; Some kind of sorting -&gt; Limit the output to X items.</p>
<p dir="auto">But I run in trouble when the input data changes. The output contains empty items. To make it work I have use beginResetModel and endResetModel, instead functions like beginRemoveRows, endRemoveRows etc. Which seems to defeat the purpose of using a QAbstractListModel.</p>
<p dir="auto">I have created a small sample project: <a href="https://gitlab.com/FinitelyFailed/qt-list-limited" target="_blank" rel="noopener noreferrer nofollow ugc">https://gitlab.com/FinitelyFailed/qt-list-limited</a><br />
<img src="https://ddgobkiprc33d.cloudfront.net/3a3ef4c9-ed99-453a-ae41-a1f934b5d8f1.png" alt="swappy-20260326_224029.png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://forum.qt.io/topic/164492/qt-qml-how-to-chain-qabstractlistmodel-and-qsortfilterproxymodel</link><generator>RSS for Node</generator><lastBuildDate>Sun, 24 May 2026 13:29:35 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/164492.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 27 Mar 2026 10:18:30 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QT QML How to chain QAbstractListModel and QSortFilterProxyModel on Fri, 27 Mar 2026 22:43:35 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/zapfyr">@<bdi>Zapfyr</bdi></a> said in <a href="/post/837365">QT QML How to chain QAbstractListModel and QSortFilterProxyModel</a>:</p>
<blockquote>
<p dir="auto">Limit the output to X items.</p>
</blockquote>
<p dir="auto">This sounds like the job of the view. Provide space to display X items, and omit the ability to navigate further.</p>
]]></description><link>https://forum.qt.io/post/837378</link><guid isPermaLink="true">https://forum.qt.io/post/837378</guid><dc:creator><![CDATA[jeremy_k]]></dc:creator><pubDate>Fri, 27 Mar 2026 22:43:35 GMT</pubDate></item><item><title><![CDATA[Reply to QT QML How to chain QAbstractListModel and QSortFilterProxyModel on Fri, 27 Mar 2026 13:06:28 GMT]]></title><description><![CDATA[<p dir="auto">Thanks for your answer. We use 6.5.3 and for some projects 6.8.3.<br />
I'll checkout QSJsonListModel.</p>
<p dir="auto">What the difference between the old SortFilterProxyModel and the new one?</p>
<p dir="auto">Where should I start to implement a limit filter from scratch?</p>
]]></description><link>https://forum.qt.io/post/837369</link><guid isPermaLink="true">https://forum.qt.io/post/837369</guid><dc:creator><![CDATA[Zapfyr]]></dc:creator><pubDate>Fri, 27 Mar 2026 13:06:28 GMT</pubDate></item><item><title><![CDATA[Reply to QT QML How to chain QAbstractListModel and QSortFilterProxyModel on Fri, 27 Mar 2026 11:37:04 GMT]]></title><description><![CDATA[<p dir="auto">I haven't ran your example but note that using QSFPM is not a good base for your LimitFilter unless you use some workarounds.<br />
QSFPM doesn't re-run the filters for accepted rows when a new row is added.<br />
If you are limiting to 1 row, and a new row is inserted first, your model will have 2 rows, the previous first row and the new one.<br />
You could fake a dataChanged on the previous row to force a call to <code>filterAcceptsRow</code>.</p>
<p dir="auto">If you want a 3rd party model doing the work of your JSON to QAIM there's <a href="https://github.com/benlau/qsyncable" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/benlau/qsyncable</a> and its QSJsonListModel.<br />
There's also now a new SortFilterProxyModel available in QML, for previous Qt versions there are multiple on Github.<br />
For the LimitFilter I don't know of any from the top of my head but I guess there are some available, or reimplement it yourself but keep the QSFPM limitation in minds. It's was designed to work on the intrinsic data of a row, not it's relative position in the model.</p>
]]></description><link>https://forum.qt.io/post/837366</link><guid isPermaLink="true">https://forum.qt.io/post/837366</guid><dc:creator><![CDATA[GrecKo]]></dc:creator><pubDate>Fri, 27 Mar 2026 11:37:04 GMT</pubDate></item></channel></rss>