PDA

View Full Version : QFile Seeking / Overwriting



tntcoda
13th November 2008, 18:55
Hi,

Is it possible with QFile to seek to an offset in a file and overwrite a set amount of existing bytes?

I can use QFile.seek() to go to a position in the file, but anything I write overwrites the entire file, rather than overwriting X number of bytes from where i seeked to :(. I opened the file with WriteOnly mode.

I want to avoid reading in the entire file, editing the bits i need to and writing it all out again. And instead just wirte data out to a specific location in the file.

Thanks for any help,

Jack

^NyAw^
13th November 2008, 19:22
Hi,

Maybe you have to read the file to a QByteArray and overwrite the date on it. Then you have to save the file with this new data.

tntcoda
13th November 2008, 19:54
Hi,

Maybe you have to read the file to a QByteArray and overwrite the date on it. Then you have to save the file with this new data.

Thanks, but the file in question might be > 4GB in size, so i cant really read it all and process it due to performance reasons. Im pretty sure it can be done in standard C but i was wondering if Qt had a way to do it. :confused:

^NyAw^
13th November 2008, 20:02
Hi,

Open the QFile and use a QDataStream on it. Then you can use:

bool QIODevice::seek ( qint64 (file:///C:/Qt/4.3.0/doc/html/qtglobal.html#qint64-typedef) pos )