PDA

View Full Version : Writing to file at specific



safknw
30th November 2006, 14:27
I'm trying to write 1 kb at start of file, file size is 5mb. I'm using QFile object, it truncate file to 1kb. I want to keep rest of file as it is. I only want to change initial 1kb. How can I do this?

wysota
30th November 2006, 14:44
Open in QIODevice::Append mode and then seek to the beginning of the file before writing.

safknw
1st December 2006, 10:30
Open in QIODevice::Append mode and then seek to the beginning of the file before writing.
I don't want to append to file i want to replace 1st kb of data on file.

wysota
1st December 2006, 12:12
I know, but you still have to open in append mode, otherwise your file will be truncated. After you open in append, you can seek to the beginning of the file and replace its contents there.