<?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 write and read a QList with binary files]]></title><description><![CDATA[<p dir="auto">I'm stuck when i tried to  read a qlist inside a binary file someone can show me how to do it because I've been trying  to do it, but I cant</p>
]]></description><link>https://forum.qt.io/topic/46017/how-to-write-and-read-a-qlist-with-binary-files</link><generator>RSS for Node</generator><lastBuildDate>Sat, 29 Aug 2026 20:46:45 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/46017.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 16 Sep 2014 16:41:33 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to write and read a QList with binary files on Thu, 18 Sep 2014 22:17:48 GMT]]></title><description><![CDATA[<p dir="auto">When you want to write/read a QList using <em>operator&gt;&gt;()</em>/<em>operator&lt;&lt;()</em>, as the doc says, the type of the QList must also implement the SAME operator.</p>
<p dir="auto">Which means that except Qt's included types (<em>quint</em>, <em>QString</em>, <em>QByteArray</em>, ...), you need to provide such an operator for your type.</p>
<p dir="auto">I see you have provided one, and you're pointing out a problem when using it on another QList (line 8: list-&gt;register). Is there a stream operator defined for the type of element in <em>list-&gt;register</em> ?</p>
]]></description><link>https://forum.qt.io/post/244454</link><guid isPermaLink="true">https://forum.qt.io/post/244454</guid><dc:creator><![CDATA[Max13]]></dc:creator><pubDate>Thu, 18 Sep 2014 22:17:48 GMT</pubDate></item><item><title><![CDATA[Reply to How to write and read a QList with binary files on Wed, 17 Sep 2014 01:44:27 GMT]]></title><description><![CDATA[<p dir="auto">it seem what the error is in this line<br />
@QDataStream&amp; operator&gt;&gt;(QDataStream &amp;out, car *&amp;list)<br />
{<br />
QString w,x,y,z;<br />
out&gt;&gt;w;<br />
out&gt;&gt;x;<br />
out&gt;&gt;y;<br />
out&gt;&gt;z;<br />
out&gt;&gt;list-&gt;register; //&lt;--- It seems this is the line with the error<br />
list-&gt;plate=w;<br />
list-&gt;brand=x;<br />
list-&gt;mileage=y.toDouble();<br />
list-&gt;cylinder_capacity=z.toDouble();<br />
return out;<br />
}@<br />
in this part register is a qlist too</p>
]]></description><link>https://forum.qt.io/post/244127</link><guid isPermaLink="true">https://forum.qt.io/post/244127</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Wed, 17 Sep 2014 01:44:27 GMT</pubDate></item><item><title><![CDATA[Reply to How to write and read a QList with binary files on Wed, 17 Sep 2014 00:18:35 GMT]]></title><description><![CDATA[<p dir="auto">ok thanks for the information i just do what you said but still when i run the program qt says:<br />
The program has unexpectedly finished.<br />
and I dont know if this error is because I'm  savin wrong at the end of the program or I'm reading wrong the binary file at the start</p>
<p dir="auto">here is where I write<br />
@QFile file("register.txt");<br />
if (file.open(QIODevice::WriteOnly))<br />
{<br />
QDataStream out(&amp;file);<br />
out &lt;&lt; cars;<br />
file.close();<br />
}@</p>
]]></description><link>https://forum.qt.io/post/244125</link><guid isPermaLink="true">https://forum.qt.io/post/244125</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Wed, 17 Sep 2014 00:18:35 GMT</pubDate></item><item><title><![CDATA[Reply to How to write and read a QList with binary files on Wed, 17 Sep 2014 00:07:29 GMT]]></title><description><![CDATA[<p dir="auto">[quote]but givesme an error[/quote]<br />
Could you post an error message here.</p>
<p dir="auto">I see couple things here</p>
<ul>
<li>
<p dir="auto">these lines should give an error on compilation<br />
@<br />
list-&gt;=mileage.toDouble();<br />
list-&gt;=cylinder_capacity.toDouble();<br />
@</p>
</li>
<li>
<p dir="auto">here you defined operator for output but trying to read from the stream<br />
@<br />
QDataStream&amp; operator&lt;&lt;(QDataStream &amp;out, QList&lt;gasoline*&gt; &amp;list)<br />
{<br />
...<br />
out &gt;&gt; petrol;<br />
...<br />
}<br />
@</p>
</li>
</ul>
<p dir="auto">You don't need to define stream operator for QList&lt;gasoline*&gt;<br />
As "<em>Max13</em> said":<a href="http://qt-project.org/forums/viewthread/47469/#194374" target="_blank" rel="noopener noreferrer nofollow ugc">http://qt-project.org/forums/viewthread/47469/#194374</a> you need to define a stream operator for gasoline.<br />
QList will use it.</p>
]]></description><link>https://forum.qt.io/post/244124</link><guid isPermaLink="true">https://forum.qt.io/post/244124</guid><dc:creator><![CDATA[andreyc]]></dc:creator><pubDate>Wed, 17 Sep 2014 00:07:29 GMT</pubDate></item><item><title><![CDATA[Reply to How to write and read a QList with binary files on Tue, 16 Sep 2014 23:58:11 GMT]]></title><description><![CDATA[<p dir="auto">when i tried to read te file givesme an error</p>
<p dir="auto">@   QFile read("register.txt");<br />
if(read.exists()){<br />
if (read.open(QIODevice::ReadOnly)){;<br />
QDataStream in(&amp;read);<br />
in &gt;&gt; cars;<br />
read.close();<br />
}<br />
}@<br />
here is when i am reading<br />
cars is my qlist of car</p>
]]></description><link>https://forum.qt.io/post/244122</link><guid isPermaLink="true">https://forum.qt.io/post/244122</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Tue, 16 Sep 2014 23:58:11 GMT</pubDate></item><item><title><![CDATA[Reply to How to write and read a QList with binary files on Tue, 16 Sep 2014 23:26:56 GMT]]></title><description><![CDATA[<p dir="auto">hey,  guys I almost end my program but givesme an error qhen i tried to take out a qlist from one of my variables car here is the code who is giving me problesma;<br />
@QDataStream&amp; operator&gt;&gt;(QDataStream &amp;out, car *&amp;list)<br />
{<br />
QString w,x,y,z;<br />
out&gt;&gt;w;<br />
out&gt;&gt;x;<br />
out&gt;&gt;y;<br />
out&gt;&gt;z;<br />
out&gt;&gt;list-&gt;register;<br />
list-&gt;plate=w;<br />
list-&gt;brand=x;<br />
list-&gt;=mileage.toDouble();<br />
list-&gt;=cylinder_capacity.toDouble();<br />
return out;<br />
}<br />
@<br />
Here is it where I overload</p>
<p dir="auto">@QDataStream&amp; operator&lt;&lt;(QDataStream &amp;out, QList&lt;gasoline*&gt; &amp;list)<br />
{<br />
while (!out.atEnd())<br />
{<br />
gasoline* petrol  = new gasoline();<br />
out &gt;&gt; petrol;<br />
list.append(petrol);<br />
}<br />
return out;<br />
}@</p>
]]></description><link>https://forum.qt.io/post/244119</link><guid isPermaLink="true">https://forum.qt.io/post/244119</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Tue, 16 Sep 2014 23:26:56 GMT</pubDate></item><item><title><![CDATA[Reply to How to write and read a QList with binary files on Tue, 16 Sep 2014 19:22:18 GMT]]></title><description><![CDATA[<p dir="auto">what woul happend if i want to write a qlist of objects who have a qlist inside them on the binary file?</p>
<p dir="auto">should I overload all the &lt;&lt;and&gt;&gt; for all the classes?</p>
]]></description><link>https://forum.qt.io/post/244087</link><guid isPermaLink="true">https://forum.qt.io/post/244087</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Tue, 16 Sep 2014 19:22:18 GMT</pubDate></item><item><title><![CDATA[Reply to How to write and read a QList with binary files on Tue, 16 Sep 2014 18:54:53 GMT]]></title><description><![CDATA[<p dir="auto">[quote author="ricardo210" date="1410893187"]and sorry for all this questions and stuff  is just I'm new in this[/quote]<br />
This forum was created to help the developers who uses Qt to find the answers on their ultimate questions. So, without the questions the forum will die.</p>
]]></description><link>https://forum.qt.io/post/244084</link><guid isPermaLink="true">https://forum.qt.io/post/244084</guid><dc:creator><![CDATA[andreyc]]></dc:creator><pubDate>Tue, 16 Sep 2014 18:54:53 GMT</pubDate></item><item><title><![CDATA[Reply to How to write and read a QList with binary files on Tue, 16 Sep 2014 18:49:10 GMT]]></title><description><![CDATA[<p dir="auto">If you define operator&gt;&gt; as a member of a class then you need only one parameter <em>QDataStream&amp;</em><br />
If you define operator as an external function then you need two.<br />
QList uses external functions because QList does not know anything about its content except of a type.<br />
Move the operator declarations out of <em>car</em> class and it should work.</p>
]]></description><link>https://forum.qt.io/post/244082</link><guid isPermaLink="true">https://forum.qt.io/post/244082</guid><dc:creator><![CDATA[andreyc]]></dc:creator><pubDate>Tue, 16 Sep 2014 18:49:10 GMT</pubDate></item><item><title><![CDATA[Reply to How to write and read a QList with binary files on Tue, 16 Sep 2014 18:46:27 GMT]]></title><description><![CDATA[<p dir="auto">and sorry for all this questions and stuff  is just I'm new in this</p>
]]></description><link>https://forum.qt.io/post/244081</link><guid isPermaLink="true">https://forum.qt.io/post/244081</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Tue, 16 Sep 2014 18:46:27 GMT</pubDate></item><item><title><![CDATA[Reply to How to write and read a QList with binary files on Tue, 16 Sep 2014 18:36:15 GMT]]></title><description><![CDATA[<p dir="auto">Hey, I do what you say but now gives me this error</p>
<p dir="auto">QDataStream&amp; car::operator&gt;&gt;(QDataStream&amp;, car*)' must take exactly one argument<br />
QDataStream &amp; operator&gt;&gt;(QDataStream &amp; in, car* aCar);<br />
^</p>
]]></description><link>https://forum.qt.io/post/244077</link><guid isPermaLink="true">https://forum.qt.io/post/244077</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Tue, 16 Sep 2014 18:36:15 GMT</pubDate></item><item><title><![CDATA[Reply to How to write and read a QList with binary files on Tue, 16 Sep 2014 18:24:08 GMT]]></title><description><![CDATA[<p dir="auto">You need to define the stream operators for your class<br />
@<br />
QDataStream &amp; operator&gt;&gt;(QDataStream &amp; in, car* aCar)<br />
QDataStream &amp; operator&lt;&lt;(QDataStream &amp; out, car* aCar)<br />
@<br />
QList will call the stream operator for each its element.</p>
]]></description><link>https://forum.qt.io/post/244071</link><guid isPermaLink="true">https://forum.qt.io/post/244071</guid><dc:creator><![CDATA[andreyc]]></dc:creator><pubDate>Tue, 16 Sep 2014 18:24:08 GMT</pubDate></item><item><title><![CDATA[Reply to How to write and read a QList with binary files on Tue, 16 Sep 2014 18:23:40 GMT]]></title><description><![CDATA[<p dir="auto">Yes, it's written in the doc:</p>
<p dir="auto">bq. This function requires the value type to implement operator&gt;&gt;()</p>
<p dir="auto">You have to define the operator, natively the compiler doesn't know how to write your type:</p>
<p dir="auto">@QDataStream &amp; operator&lt;&lt;(QDataStream &amp; stream, const MyType &amp; myVar)@</p>
<p dir="auto">And don't forget, the pointer is just a pointer (so it's just an address), you should dereference it, but it's up to you when you define your operator&lt;&lt;(). If your <em>QList</em> is defined with pointers, you will define <em>operator&lt;&lt;()</em> with pointer as the second type.</p>
]]></description><link>https://forum.qt.io/post/244070</link><guid isPermaLink="true">https://forum.qt.io/post/244070</guid><dc:creator><![CDATA[Max13]]></dc:creator><pubDate>Tue, 16 Sep 2014 18:23:40 GMT</pubDate></item><item><title><![CDATA[Reply to How to write and read a QList with binary files on Tue, 16 Sep 2014 18:11:57 GMT]]></title><description><![CDATA[<p dir="auto">yes I tried but  gives me an error:</p>
<p dir="auto">no match for 'operator&gt;&gt;' (operand types are 'QDataStream' and 'car*')<br />
s &gt;&gt; t;<br />
^</p>
]]></description><link>https://forum.qt.io/post/244069</link><guid isPermaLink="true">https://forum.qt.io/post/244069</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Tue, 16 Sep 2014 18:11:57 GMT</pubDate></item><item><title><![CDATA[Reply to How to write and read a QList with binary files on Tue, 16 Sep 2014 17:06:37 GMT]]></title><description><![CDATA[<p dir="auto">Have you tried to write the list to a file using the operator &gt;&gt; to a QDataStream?</p>
<p dir="auto">"<a href="http://qt-project.org/doc/qt-5/qlist.html#operator-gt-gt-61" target="_blank" rel="noopener noreferrer nofollow ugc">http://qt-project.org/doc/qt-5/qlist.html#operator-gt-gt-61</a>":<a href="http://qt-project.org/doc/qt-5/qlist.html#operator-gt-gt-61" target="_blank" rel="noopener noreferrer nofollow ugc">http://qt-project.org/doc/qt-5/qlist.html#operator-gt-gt-61</a></p>
]]></description><link>https://forum.qt.io/post/244055</link><guid isPermaLink="true">https://forum.qt.io/post/244055</guid><dc:creator><![CDATA[Max13]]></dc:creator><pubDate>Tue, 16 Sep 2014 17:06:37 GMT</pubDate></item></channel></rss>