<?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[How to address all the ListModel ListElements and not just one?]]></title><description><![CDATA[<p dir="auto">Hi gurus,<br />
Another one riddle (more like a clarification needed)<br />
I have the following vendorList:</p>
<p dir="auto">@ListModel {<br />
id: vendorsModel<br />
ListElement {<br />
vendortitle: "Vendor"<br />
vendorlogo: "images/vendorlogo.png"<br />
openhours: "10am-5am"<br />
favorite: 0<br />
averagedeliverytime: "1h"<br />
additionalinfo: "this is some additional information here"<br />
}<br />
ListElement {<br />
vendortitle: "Vendor1"<br />
vendorlogo: "images/vendor2logo.png"<br />
openhours: "10am-5am"<br />
favorite: 0<br />
averagedeliverytime: "1h"<br />
additionalinfo: "this is some additional information here"<br />
}@</p>
<p dir="auto">There is a property "favorite" that can change to 1 if user toggles the button.<br />
I want to implement a button that resets all the favorites in all the ListElements to 0 (like Reset All button).</p>
<p dir="auto">Is there a technique to do that?<br />
or I need to address each and every ListElement via something like: ListModel::setProperty ( int index, string property, variant value )?</p>
]]></description><link>https://forum.qt.io/topic/5282/how-to-address-all-the-listmodel-listelements-and-not-just-one</link><generator>RSS for Node</generator><lastBuildDate>Sat, 22 Aug 2026 07:55:12 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/5282.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 22 Apr 2011 16:34:24 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to address all the ListModel ListElements and not just one? on Wed, 27 Apr 2011 17:08:52 GMT]]></title><description><![CDATA[<p dir="auto">Ah I see...thanks!;) that helps to address similar issues as well...but I definitely need an upgrade...(of my expertise...)</p>
]]></description><link>https://forum.qt.io/post/85592</link><guid isPermaLink="true">https://forum.qt.io/post/85592</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Wed, 27 Apr 2011 17:08:52 GMT</pubDate></item><item><title><![CDATA[Reply to How to address all the ListModel ListElements and not just one? on Wed, 27 Apr 2011 06:27:35 GMT]]></title><description><![CDATA[<p dir="auto">@<br />
function totalFavorites() {<br />
var result = 0<br />
for (var i=0; i &lt; vendorsModel.count; i++)<br />
result += vendorsModel.get(i).favorite<br />
return result<br />
}<br />
@</p>
]]></description><link>https://forum.qt.io/post/85492</link><guid isPermaLink="true">https://forum.qt.io/post/85492</guid><dc:creator><![CDATA[DenisKormalev]]></dc:creator><pubDate>Wed, 27 Apr 2011 06:27:35 GMT</pubDate></item><item><title><![CDATA[Reply to How to address all the ListModel ListElements and not just one? on Wed, 27 Apr 2011 04:59:07 GMT]]></title><description><![CDATA[<p dir="auto">Hi folks, sorry but I am quite a noob in all of that hence some things are harder to understand (yet). But your help is supr appreciated...</p>
<p dir="auto">So basically what I achieved so far is to insert this function below into QML element:</p>
<p dir="auto">@Text {<br />
id: favoritesTab<br />
function totalFavorites() {<br />
for (var i=0; i &lt; vendorsModel.count; i++)<br />
return vendorsModel.get(i).favorite<br />
}<br />
text: "Favorites:" + totalFavorites()@</p>
<p dir="auto">As seen from the JS code I am only getting returned value for the first ListElement...I am now trying to implement somthing that will just sum-up the returned looped items...</p>
<p dir="auto">How can I add ssomething like: @return SUM(vendorsModel.get(i).favorite)@</p>
]]></description><link>https://forum.qt.io/post/85479</link><guid isPermaLink="true">https://forum.qt.io/post/85479</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Wed, 27 Apr 2011 04:59:07 GMT</pubDate></item><item><title><![CDATA[Reply to How to address all the ListModel ListElements and not just one? on Tue, 26 Apr 2011 22:01:04 GMT]]></title><description><![CDATA[<p dir="auto">You have "while" and "for" loops in almost every program language you can think of. I like the foreach loop wich Qt provides. (its not a standard c++ loop)</p>
]]></description><link>https://forum.qt.io/post/85452</link><guid isPermaLink="true">https://forum.qt.io/post/85452</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Tue, 26 Apr 2011 22:01:04 GMT</pubDate></item><item><title><![CDATA[Reply to How to address all the ListModel ListElements and not just one? on Tue, 26 Apr 2011 20:09:35 GMT]]></title><description><![CDATA[<p dir="auto">Hmm...Andre, you probably right, but I am a real rookie in C++ yet and for now I need to complete the demo based on QML and maybe javascript that I have some understanding...</p>
<p dir="auto">Denis, you mentioned simple loop? what does it mean? do you mean to do it in JS? or is there QML based method to do it? any suggestion is very welcomed!</p>
]]></description><link>https://forum.qt.io/post/85441</link><guid isPermaLink="true">https://forum.qt.io/post/85441</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Tue, 26 Apr 2011 20:09:35 GMT</pubDate></item><item><title><![CDATA[Reply to How to address all the ListModel ListElements and not just one? on Sun, 24 Apr 2011 10:06:14 GMT]]></title><description><![CDATA[<p dir="auto">I assume that at one point, you will want to start using a real model that supports persistence instead of the fixed model you use now, right? In that case, you could simply use a custom model in C++ that you use from QML. And that custom model could simply have a resetFavorites() slots you can call from your QML.</p>
]]></description><link>https://forum.qt.io/post/85133</link><guid isPermaLink="true">https://forum.qt.io/post/85133</guid><dc:creator><![CDATA[andre]]></dc:creator><pubDate>Sun, 24 Apr 2011 10:06:14 GMT</pubDate></item><item><title><![CDATA[Reply to How to address all the ListModel ListElements and not just one? on Sat, 23 Apr 2011 14:47:37 GMT]]></title><description><![CDATA[<p dir="auto">There is no such method to do it in ListModel, but iterating through elements and use setProperty for them is not a something hard. Simple loop from 0 to count with one operation.</p>
]]></description><link>https://forum.qt.io/post/85077</link><guid isPermaLink="true">https://forum.qt.io/post/85077</guid><dc:creator><![CDATA[DenisKormalev]]></dc:creator><pubDate>Sat, 23 Apr 2011 14:47:37 GMT</pubDate></item></channel></rss>