Results 1 to 2 of 2

Thread: QDataStream

  1. #1
    Join Date
    Mar 2006
    Location
    USA
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QDataStream - add to/change existing serialized binary file

    Hi,

    I would like to use QDataStream to serialize data and store to a binary file. Later on, I would like to add to the file, or change certain contents. Is this possible? I am reading the description of the QDataStream class, and it does not appear to allow for adding to, or modifying, a serialized data file. It looks like 'skipRawData' is the only member function that allows accessing the data in any way beyond simply reading it sequentially from the beginning.

    I could theoretically use QDataStream to read previously serialized data, make any necessary modifications/additions/subtractions, and serialize the data again, but this would become quite inefficient for large datasets. Alternatively, I could look into integrating a relational database and storing complex data that way, but it seems overkill for my purposes. Does anyone know of a way to accomplish this? I am using Qt 4.1.1 on Windows and X11, Open Source - MinGW/GCC.

    Any help is appreciated.

    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDataStream

    In general you'll always have to reread and rewrite the contents of the file, because it is not possible to "add" to the file in the middle. If you have constant size of records, then it doesn't matter and you can use QDataStream or whatever other file classes you want. But probably you'd like to allow each record to be of different size, so you'll have to rewrite the file each time you want to change the size of any record. Maybe you could use XML for this? It'll read the contents each time by itself, but it'll bloat the file a little.

Similar Threads

  1. QDataStream class/struct & stream operators
    By darksaga in forum Qt Programming
    Replies: 1
    Last Post: 1st August 2008, 19:40
  2. QDataStream and QHash<QString,QVariant> crash on read
    By ^NyAw^ in forum Qt Programming
    Replies: 1
    Last Post: 15th July 2008, 12:14
  3. QDataStream question...
    By grellsworth in forum Qt Programming
    Replies: 10
    Last Post: 21st April 2008, 12:17
  4. QDataStream use
    By Doug Broadwell in forum Qt Programming
    Replies: 2
    Last Post: 21st July 2007, 22:17
  5. QDataStream >> QString
    By smalls in forum Qt Programming
    Replies: 2
    Last Post: 17th January 2006, 22:14

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.