QDataStream write file size to file header ?
Solved
General and Desktop
-
wrote on 6 May 2018, 04:12 last edited by
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.
-
wrote on 8 May 2018, 07:59 last edited by
those 4 bytes are the lenght of the array so that you can read it back otherwise you wouldn't know where to stop...
-
wrote on 8 May 2018, 08:10 last edited by
Maybe you are looking for QTextStream ?
1/4