Results 1 to 4 of 4

Thread: QFile Seeking / Overwriting

  1. #1
    Join Date
    Jun 2008
    Location
    UK
    Posts
    35
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QFile Seeking / Overwriting

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QFile Seeking / Overwriting

    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.
    Òscar Llarch i Galán

  3. #3
    Join Date
    Jun 2008
    Location
    UK
    Posts
    35
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QFile Seeking / Overwriting

    Quote Originally Posted by ^NyAw^ View Post
    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QFile Seeking / Overwriting

    Hi,

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

    bool QIODevice::seek ( qint64 pos )
    Òscar Llarch i Galán

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.