Strange binary file output when using QByteArray.
Hi, all,
I have a problem of QByteArry.
When I take it to store a data, a strange binary file is outputted.
A basic code is like as following.
Code:
static const char mydata[] = { 0x74,0x68,0x65 };
out<<data;
However, I got a strange extra data on the head of data stream.
Why does the output data have 0000 0003 ?
Could you please help me.
Thank you very much.
Re: Strange binary file output when using QByteArray.
QDataStream is a serialization mechanism and not a general purpose binary stream. It prepended the length of the byte array to the stream to be able to deserialize it later.
Re: Strange binary file output when using QByteArray.
Just to emphasis what wysota wrote: you problem has nothing to do with QByteArray.
Write it directly into the file instead of serializing it as an object.
Cheers,
_
Re: Strange binary file output when using QByteArray.
Thank you, anda_skoa and wysota.
I will try to use std::fstream or fwrite.
Re: Strange binary file output when using QByteArray.
It is enough to use QFile::write.