Solved QDataStream write file size to file header ?
-
QDataStream write 4 more bytes to file header which seems like file size, and causes file error, file.write() will not.
QFile file(path); if (file.open(QFile::WriteOnly)) { QDataStream DS(&file); QByteArray BA = "aaaaaaaaaaa"; DS << BA; file.close(); }
QFile file(path); if (file.open(QFile::WriteOnly)) { QByteArray BA = "aaaaaaaaaaa"; file.write(BA); file.close(); }
-
And what's the actual problem? QDataStream is an internal stream format which allows you to write and read Qt data types directly to a file. Therefore it need to add some information to know which data type is there and others like e.g. it's content size.
-
those 4 bytes are the lenght of the array so that you can read it back otherwise you wouldn't know where to stop...
-
Maybe you are looking for QTextStream ?