<?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[Passing QList reference dont reflect changes like spected]]></title><description><![CDATA[<p dir="auto">Hi, learning about Model/View, create a simple program that take<br />
tablemodel.cpp and tablemodel.h from the sample<br />
<a href="http://qt-project.org/doc/qt-4.8/itemviews-addressbook.html" target="_blank" rel="noopener noreferrer nofollow ugc">http://qt-project.org/doc/qt-4.8/itemviews-addressbook.html</a></p>
<p dir="auto">I my dialog only have a button and a QTableView.<br />
the button run the next code:<br />
@ void dlgViewer::insertBtnClick()<br />
{<br />
qDebug()&lt;&lt; "Insert " ;<br />
// pairlist is defined in header like<br />
//   QList&lt;QPair&lt;QString, QString&gt; &gt; pairlist ;</p>
<pre><code> QPair&lt;QString, QString&gt; pair("name0", "address0");
 QPair&lt;QString, QString&gt; pair1("name1", "address1");
 QPair&lt;QString, QString&gt; pair2("name2", "address2");
 pairlist.append(pair);
 pairlist.append(pair1);
 pairlist.append(pair2);

 contentTableModel-&gt;setList(pairlist);
 //until here the contentTableView show the added pairs
 // the next changes not are reflected

  QPair&lt;QString, QString&gt; pair3("name3", "address3");



 pairlist.append(pair3);
 pairlist.append(pair3);

 contentTableModel-&gt;layoutChanged();

 qDebug()&lt;&lt;"pairlist count: "&lt;&lt; pairlist.count();// print 5

 qDebug()&lt;&lt;"model content count: "&lt;&lt; contentTableModel-&gt;contentCount();//print 3
</code></pre>
<p dir="auto">}<br />
@</p>
<p dir="auto">The problem is that the changes in the original list not are reflected in the  model list.<br />
Debug output is:<br />
@<br />
Insert<br />
model count befor:  0<br />
model count after:  3<br />
pairlist count:  5<br />
model content count:  3<br />
@</p>
<p dir="auto">In the contentTableView only see 3 pairs</p>
<p dir="auto">In the TableModel.cpp added a method that pass the reference to the list:</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/void">@<bdi>void</bdi></a> TableModel::setList(QList&lt;QPair&lt;QString, QString&gt; &gt; &amp;  alistofPairs)</p>
<p dir="auto">{<br />
qDebug()&lt;&lt;"model count befor: " &lt;&lt; listOfPairs.count();<br />
listOfPairs= alistofPairs;<br />
qDebug()&lt;&lt; "model count after: " &lt;&lt; listOfPairs.count();<br />
emit (layoutChanged());</p>
<p dir="auto">}@<br />
Also Qlist is Implicit Sharing that mean a shallow copy.</p>
<p dir="auto">I dont want to store my data in the model, only want to send the reference to my data<br />
What is wrong,</p>
]]></description><link>https://forum.qt.io/topic/42871/passing-qlist-reference-dont-reflect-changes-like-spected</link><generator>RSS for Node</generator><lastBuildDate>Wed, 08 Apr 2026 11:35:37 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/42871.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 23 Jun 2014 18:55:50 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Passing QList reference dont reflect changes like spected on Tue, 24 Jun 2014 12:46:51 GMT]]></title><description><![CDATA[<p dir="auto">It means that when you write something in one of the shallow copies, it will at that moment do the deep copy for that variable.</p>
<p dir="auto">Yes in that case you can use a pointer</p>
]]></description><link>https://forum.qt.io/post/233235</link><guid isPermaLink="true">https://forum.qt.io/post/233235</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Tue, 24 Jun 2014 12:46:51 GMT</pubDate></item><item><title><![CDATA[Reply to Passing QList reference dont reflect changes like spected on Mon, 23 Jun 2014 22:23:25 GMT]]></title><description><![CDATA[<p dir="auto">Sorry for my English capabilities reading the implicit sharing document dont understand the "copy-on-write"<br />
Wich would be the correct way to passing an avoid copy.<br />
Must to use a pointer ?<br />
Can give me a little code sample.</p>
<p dir="auto">Greetings</p>
]]></description><link>https://forum.qt.io/post/233130</link><guid isPermaLink="true">https://forum.qt.io/post/233130</guid><dc:creator><![CDATA[marceloarguello700]]></dc:creator><pubDate>Mon, 23 Jun 2014 22:23:25 GMT</pubDate></item><item><title><![CDATA[Reply to Passing QList reference dont reflect changes like spected on Mon, 23 Jun 2014 21:08:59 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">Shallow copy indeed but also means copy on write. Since you are modifying your list after setting in on your model you will have a new list.</p>
]]></description><link>https://forum.qt.io/post/233116</link><guid isPermaLink="true">https://forum.qt.io/post/233116</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Mon, 23 Jun 2014 21:08:59 GMT</pubDate></item></channel></rss>