<?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[Reading a binary file]]></title><description><![CDATA[<p dir="auto">hi to everyone<br />
i am trying to read a binary file and save it to my db as a blob data(qsqlite)<br />
i use this code<br />
@ QFIle myfile("1.zip");<br />
QByteArray x;<br />
if(!myfile.open())<br />
return;<br />
while(!myfile.atEnd())<br />
x = myfile.readall();<br />
QFIle myfile1("1.png");<br />
QByteArray x1;<br />
if(!myfile1.open())<br />
return;<br />
while(!myfile1.atEnd())<br />
x1 = myfile1.readall();<br />
@<br />
i think it only read the a few first charachters of my file<br />
how can i solve this?</p>
]]></description><link>https://forum.qt.io/topic/10335/reading-a-binary-file</link><generator>RSS for Node</generator><lastBuildDate>Mon, 20 Apr 2026 06:17:51 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/10335.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 12 Oct 2011 05:16:00 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Reading a binary file on Thu, 13 Oct 2011 13:36:10 GMT]]></title><description><![CDATA[<p dir="auto">You're speaking of charactares, which makes me guess that you're on the wrong concept.</p>
<p dir="auto">You <em>must not</em> print arbitrary binary data with printf() or qDebug()! As cincirin already mentioned, this stops at the first null-byte (0x00) regardless how big your data is.</p>
<p dir="auto">You <em>must</em> check the byte array's size with x.size().</p>
]]></description><link>https://forum.qt.io/post/113153</link><guid isPermaLink="true">https://forum.qt.io/post/113153</guid><dc:creator><![CDATA[goetz]]></dc:creator><pubDate>Thu, 13 Oct 2011 13:36:10 GMT</pubDate></item><item><title><![CDATA[Reply to Reading a binary file on Thu, 13 Oct 2011 13:30:33 GMT]]></title><description><![CDATA[<p dir="auto">What is the value of @x.size()@ ?</p>
]]></description><link>https://forum.qt.io/post/113154</link><guid isPermaLink="true">https://forum.qt.io/post/113154</guid><dc:creator><![CDATA[cincirin]]></dc:creator><pubDate>Thu, 13 Oct 2011 13:30:33 GMT</pubDate></item><item><title><![CDATA[Reply to Reading a binary file on Thu, 13 Oct 2011 13:26:03 GMT]]></title><description><![CDATA[<p dir="auto">yes i am sure the data is incomplete<br />
because the file is abour 200 kb but the x variable has only a few charachter(4 or 5 charachter)</p>
]]></description><link>https://forum.qt.io/post/113152</link><guid isPermaLink="true">https://forum.qt.io/post/113152</guid><dc:creator><![CDATA[kitten]]></dc:creator><pubDate>Thu, 13 Oct 2011 13:26:03 GMT</pubDate></item><item><title><![CDATA[Reply to Reading a binary file on Wed, 12 Oct 2011 09:25:24 GMT]]></title><description><![CDATA[<p dir="auto">readAll is guaranteed to read all available data, so the while loop is completely unnecessary.</p>
<p dir="auto">And so you <em>think</em> the data is incomplete? Did you proof yourself it actually <em>is</em> incomplete?</p>
]]></description><link>https://forum.qt.io/post/113003</link><guid isPermaLink="true">https://forum.qt.io/post/113003</guid><dc:creator><![CDATA[goetz]]></dc:creator><pubDate>Wed, 12 Oct 2011 09:25:24 GMT</pubDate></item><item><title><![CDATA[Reply to Reading a binary file on Wed, 12 Oct 2011 08:48:25 GMT]]></title><description><![CDATA[<p dir="auto">Additionally, if readall does not return the whole file, you overwrite the previous data.</p>
<p dir="auto">@<br />
while(!myfile.atEnd())<br />
x += myfile.readall();<br />
@</p>
<p dir="auto">or remove the while loop.</p>
]]></description><link>https://forum.qt.io/post/112999</link><guid isPermaLink="true">https://forum.qt.io/post/112999</guid><dc:creator><![CDATA[giesbert]]></dc:creator><pubDate>Wed, 12 Oct 2011 08:48:25 GMT</pubDate></item><item><title><![CDATA[Reply to Reading a binary file on Wed, 12 Oct 2011 07:00:48 GMT]]></title><description><![CDATA[<p dir="auto">bq. QByteArray can be used to store both raw bytes (including '\0's) and traditional 8-bit '\0'-terminated strings<br />
Behind the scenes, it always ensures that the data is followed by a '\0' terminator</p>
<p dir="auto">Perhaps this is the reason why you <em>see only</em> part of the array.</p>
]]></description><link>https://forum.qt.io/post/112964</link><guid isPermaLink="true">https://forum.qt.io/post/112964</guid><dc:creator><![CDATA[cincirin]]></dc:creator><pubDate>Wed, 12 Oct 2011 07:00:48 GMT</pubDate></item><item><title><![CDATA[Reply to Reading a binary file on Wed, 12 Oct 2011 06:06:31 GMT]]></title><description><![CDATA[<p dir="auto">I don't understand what the problem is. How can you say that only a few data is read from the file?</p>
]]></description><link>https://forum.qt.io/post/112959</link><guid isPermaLink="true">https://forum.qt.io/post/112959</guid><dc:creator><![CDATA[fluca1978]]></dc:creator><pubDate>Wed, 12 Oct 2011 06:06:31 GMT</pubDate></item></channel></rss>