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

Nikita Krupenko krnekit at gmail.com
Tue Mar 8 20:49:39 CET 2016


2016-03-08 21:43 GMT+02:00 Thiago Macieira <thiago.macieira at intel.com>:
> On terça-feira, 8 de março de 2016 21:27:52 PST Nikita Krupenko wrote:
>> 2016-03-08 19:30 GMT+02:00 Thiago Macieira <thiago.macieira at intel.com>:
>> > Indeed, but look at how you've combined two or more examples. You have a
>> > byte array, you create a QDataStream on it, write some data, then you
>> > used QDataStream to write that byte array to another byte array. You
>> > probably didn't want that.
>>
>> It could be useful, if I want to write checksum of the data to the
>> file. To do this, I can write
>> some data to the QByteArray wrapped in QDataStream, then calculate
>> checksum using
>> qChecksum() (or QCriptographicHash) and then write byte array and
>> checksum to the file.
>
> You could do that, but this is not what I was talking about.
>
> The problem was that Sina caused redundancy in the data:
>
> <32-bit value N+4> <32-bit value N/2> <string of length N/2>
>
> Do you see the redundancy?
>
> In your case, just make sure you don't use QDataStream to write the bytearray
> that was check-summed, or you'll do the same as the above.

I mean, in general it could be useful. I agree, in the example of Sina
it's just redundant.



More information about the Interest mailing list