How to write QByteArray to Position 0
-
hi,
does anybody know how I can write a QByteArray at Position 0 (start)
of a file. (i want to create a header)It is an embedded system so I have not enough memory
to read the whole file and append it to the header array.thx
-
You may shift the file chunk-by-chunk, saving these small amounts of data into a small buffer.
-
.
-
bool QFile::seek ( qint64 pos ) can't help?
-
if I write seek(0) and then write(data) will the data be written
to this place whithout deleting the existing data? -
from doc of QFile::seek()
bq. If a write is performed at this position, then the file shall be extended. The content of the file between the previous end of file and the newly written data is UNDEFINED and varies between platforms and file systems.
-
The data will be overwritten after seeking to 0.
-
[quote author="gandiii" date="1353589552"]if I write seek(0) and then write(data) will the data be written
to this place whithout deleting the existing data?[/quote]As I know, the seek() only put your "cursor" into a given position.
If your position is IN a filled dataarea, your write() will overwrite that data. Anyway you will write into a virgin area... -
Another solution: use the QTemporaryFile write the header here, and after this, you can append the second file after the first temporary file, or something similar ...