<?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[extending functionality of a proxy model]]></title><description><![CDATA[<p dir="auto">Hi all -</p>
<p dir="auto">I've implemented a proxy model that filters based on a property of the item. I want to use this proxy model in different places, but with additional filtering. Here's a code snippet:</p>
<pre><code>class Equipment : public QObject
{
    Q_OBJECT
    QML_ELEMENT

    Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged FINAL)
    ...
}
    
QList&lt;Equipment *&gt; EquipmentValveProxy::getReturn()
{
    QList&lt;Equipment *&gt; list;
    ... // conditionally add stuff to list.
    return list;
}
</code></pre>
<p dir="auto">I try to use this function in QML as follows:</p>
<pre><code>ListView {
    model: equipmentValveProxy.getReturn()
    delegate: valveName
    Component {
        id: valveName
        Label { text: name } // runtime error: not defined.
    }
</code></pre>
<p dir="auto">but "name" isn't recognized here. Is what I'm trying to do even possible? Or do I need a new proxy model for this purpose?</p>
<p dir="auto">Thanks...</p>
]]></description><link>https://forum.qt.io/topic/155920/extending-functionality-of-a-proxy-model</link><generator>RSS for Node</generator><lastBuildDate>Mon, 06 Apr 2026 07:08:31 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/155920.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 09 Apr 2024 16:41:58 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to extending functionality of a proxy model on Wed, 10 Apr 2024 15:28:49 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mzimmers">@<bdi>mzimmers</bdi></a> Use multiple proxy models. Expose your proxy model as a type with some properties to tweak the criterias as you need instead of having a single one..</p>
<p dir="auto">Views should instantiate their proxy models.</p>
<p dir="auto">Keep a single source model though because that is your data and it belongs in c++.</p>
]]></description><link>https://forum.qt.io/post/796386</link><guid isPermaLink="true">https://forum.qt.io/post/796386</guid><dc:creator><![CDATA[GrecKo]]></dc:creator><pubDate>Wed, 10 Apr 2024 15:28:49 GMT</pubDate></item><item><title><![CDATA[Reply to extending functionality of a proxy model on Wed, 10 Apr 2024 16:58:09 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/grecko">@<bdi>GrecKo</bdi></a> said in <a href="/post/796386">extending functionality of a proxy model</a>:</p>
<blockquote>
<p dir="auto">Use multiple proxy models.</p>
</blockquote>
<p dir="auto">OK, will do. I wasn't sure whether this was a viable alternative, or if I should somehow use proxy models as sparingly as possible.</p>
<blockquote>
<p dir="auto">Expose your proxy model as a type with some properties...</p>
</blockquote>
<p dir="auto">I'm not sure I understand what this means.</p>
<p dir="auto">Thanks...</p>
]]></description><link>https://forum.qt.io/post/796396</link><guid isPermaLink="true">https://forum.qt.io/post/796396</guid><dc:creator><![CDATA[mzimmers]]></dc:creator><pubDate>Wed, 10 Apr 2024 16:58:09 GMT</pubDate></item><item><title><![CDATA[Reply to extending functionality of a proxy model on Wed, 10 Apr 2024 15:28:49 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mzimmers">@<bdi>mzimmers</bdi></a> Use multiple proxy models. Expose your proxy model as a type with some properties to tweak the criterias as you need instead of having a single one..</p>
<p dir="auto">Views should instantiate their proxy models.</p>
<p dir="auto">Keep a single source model though because that is your data and it belongs in c++.</p>
]]></description><link>https://forum.qt.io/post/796386</link><guid isPermaLink="true">https://forum.qt.io/post/796386</guid><dc:creator><![CDATA[GrecKo]]></dc:creator><pubDate>Wed, 10 Apr 2024 15:28:49 GMT</pubDate></item><item><title><![CDATA[Reply to extending functionality of a proxy model on Wed, 10 Apr 2024 15:13:38 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/grecko">@<bdi>GrecKo</bdi></a> said in <a href="/post/796384">extending functionality of a proxy model</a>:</p>
<blockquote>
<p dir="auto">If you correctly implemented your proxy you should use it as such: model: equipmentValveProxy</p>
</blockquote>
<p dir="auto">I do use it exactly that way elsewhere.</p>
<p dir="auto">My situation is that I need to display various subsets of the equipment model in different parts of the UI. Even the valve subset will require different selection criteria on different views. What I really need, probably, is some way to make filterAcceptRows() smarter, so it would behave differently based on the use case. Absent that, this function that returns a list (and I'd have more functions like it) was the best I could think of.</p>
]]></description><link>https://forum.qt.io/post/796385</link><guid isPermaLink="true">https://forum.qt.io/post/796385</guid><dc:creator><![CDATA[mzimmers]]></dc:creator><pubDate>Wed, 10 Apr 2024 15:13:38 GMT</pubDate></item><item><title><![CDATA[Reply to extending functionality of a proxy model on Wed, 10 Apr 2024 15:02:30 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mzimmers">@<bdi>mzimmers</bdi></a> said in <a href="/post/796380">extending functionality of a proxy model</a>:</p>
<blockquote>
<p dir="auto">I know - I left that out for brevity.</p>
</blockquote>
<p dir="auto">but you use <code>model: equipmentValveProxy.getReturn()</code>  with a function signature of <code>QList&lt;Equipment *&gt; EquipmentValveProxy::getReturn()</code></p>
<p dir="auto">You are not using it as a QSortFilterProxyModel and it inheriting QSortFilterProxyModel has no effect in the code you provided.</p>
<p dir="auto">If you correctly implemented your proxy you should use it as such: <code>model: equipmentValveProxy</code></p>
]]></description><link>https://forum.qt.io/post/796384</link><guid isPermaLink="true">https://forum.qt.io/post/796384</guid><dc:creator><![CDATA[GrecKo]]></dc:creator><pubDate>Wed, 10 Apr 2024 15:02:30 GMT</pubDate></item><item><title><![CDATA[Reply to extending functionality of a proxy model on Wed, 10 Apr 2024 14:43:09 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/grecko">@<bdi>GrecKo</bdi></a> said in <a href="/post/796369">extending functionality of a proxy model</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mzimmers">@<bdi>mzimmers</bdi></a> why would <code>name</code> be recognized?</p>
<p dir="auto">You are using a QList as a model. QList is not a QAbstractItemModel and thus don't have model role. This means that the ListView is only exposing the elements of the list to the delegates via <code>modelData</code>. <code>text: modelData.name</code> would work in your case.</p>
</blockquote>
<p dir="auto">Aha.</p>
<p dir="auto">Your solution works, but your answer made me realize I have another issue with this approach: by use of a simple list, my UI won't be updated automatically when the model changes. I can see I still have some work to do.</p>
<blockquote>
<p dir="auto">Also when talking about proxy model in Qt we usually mean <a href="https://doc.qt.io/qt-6/qabstractproxymodel.html" target="_blank" rel="noopener noreferrer nofollow ugc"><code>QAbstractProxyModel</code></a> like <code>QSortFilterProxyModel</code>. They operate over a <code>QAbstractListModel</code>. You don't have any of those in your above code.</p>
</blockquote>
<p dir="auto">I know - I left that out for brevity.</p>
<pre><code>class EquipmentValveProxy : public QSortFilterProxyModel
{
    Q_OBJECT
    ...
</code></pre>
]]></description><link>https://forum.qt.io/post/796380</link><guid isPermaLink="true">https://forum.qt.io/post/796380</guid><dc:creator><![CDATA[mzimmers]]></dc:creator><pubDate>Wed, 10 Apr 2024 14:43:09 GMT</pubDate></item><item><title><![CDATA[Reply to extending functionality of a proxy model on Wed, 10 Apr 2024 11:08:40 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mzimmers">@<bdi>mzimmers</bdi></a> why would <code>name</code> be recognized?</p>
<p dir="auto">You are using a QList as a model. QList is not a QAbstractItemModel and thus don't have model role. This means that the ListView is only exposing the elements of the list to the delegates via <code>modelData</code>. <code>text: modelData.name</code> would work in your case.</p>
<p dir="auto">Also when talking about proxy model in Qt we usually mean <a href="https://doc.qt.io/qt-6/qabstractproxymodel.html" target="_blank" rel="noopener noreferrer nofollow ugc"><code>QAbstractProxyModel</code></a> like <code>QSortFilterProxyModel</code>. They operate over a <code>QAbstractListModel</code>. You don't have any of those in your above code.</p>
]]></description><link>https://forum.qt.io/post/796369</link><guid isPermaLink="true">https://forum.qt.io/post/796369</guid><dc:creator><![CDATA[GrecKo]]></dc:creator><pubDate>Wed, 10 Apr 2024 11:08:40 GMT</pubDate></item></channel></rss>