Home > Software engineering >  Error when writing data to binary file c qt
Error when writing data to binary file c qt

Time:04-30

I am making a c qt program and I need to write data to a binary file. But there's a problem. When I do this, extra empty bytes are written to the file. Here is my code:

QDataStream output(&fileOut);
QBitArray result;
result.resize(8);
result.fill(true);
output << result;

As a result, my file consists of 5 bytes instead of 1:

00000000
00000000
00000000
00001000
11111111

Does anyone know how to solve this problem?

CodePudding user response:

Using QDataStream to write binary data in any form which should not be read again by QDataStream will not work since QDataStream adds some more bytes to be able to deserialize the data later on. QDataStream is not meant to write plain data (as can be seen in the enter image description here

  •  Tags:  
  • c qt
  • Related