[Qt-interest] Write struct in a QByteArray or QFile

Thiago Macieira thiago.macieira at trolltech.com
Mon Jun 8 18:12:34 CEST 2009


Oliver.Knoll at comit.ch wrote:
> It is not very obvious from the docs
> http://doc.qtsoftware.com/4.5/qiodevice.html#write, but I think write()
> writes an 8-bit string (characters) to the file, that is it terminates
> when it encounters a NUL (\0) character (or when it has written
> 'maxSize' characters, whatever comes first). Actually the Qt docs only
> mention the string here:
> http://doc.qtsoftware.com/4.5/qiodevice.html#write-2, a method which
> was only introduced in Qt 4.5:
>
>    "Writes data from a zero-terminated string of 8-bit characters to
> the device."
>
>But I think this comment also applies to
> http://doc.qtsoftware.com/4.5/qiodevice.html#write.

No, it doesn't. The write() function writes binary data. If a size isn't 
given, then it writes until the first NUL -- but if it is given, then it 
writes exactly that many bytes.

>Especially since there are methods in the API which specifically deal
> with binary data, such as:
>
>  http://doc.qtsoftware.com/4.5/qiodevice.html#writeData

That's a protected virtual function that is called by write() to actually 
write data. It's not what you're looking for.

-- 
Thiago Macieira - thiago.macieira (AT) nokia.com
  Senior Product Manager - Nokia, Qt Software
      Sandakerveien 116, NO-0402 Oslo, Norway
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090608/ea6ba9fa/attachment.bin 


More information about the Qt-interest-old mailing list