[Interest] reading from and writing to a file with QDataStream

william.crocker at analog.com william.crocker at analog.com
Mon Mar 7 16:11:47 CET 2016


On 03/07/2016 09:35 AM, Sina Dogru wrote:
> Well but, I am writing a QString to QByteArray,
>
> QByteArray bai;
> QDataStream out(&bai, QIODevice::WriteOnly);
> out << QString("A QString");
>
> And writing an 'int' and QByteArray which a QString written
>
> file.open(QIODevice::WriteOnly);
> QDataStream out2(&file); // and module A write those datas to a file.
> out2 << bai.size();
> out2 << bai;
>

All I care about is the QDataStream.

You wrote the size() of QByteArray (which may or may not be an int)
and then you read an int.

You wrote a QByteArray and then you read a QString.
I do not care what is in the QByteArray which you wrote.

You should read back a QByteArray and then, in a subsequent
operation, extract the QString from that.

> I might screwed totally? :S
>



More information about the Interest mailing list