PDA

View Full Version : QDataStream



frankoz
1st March 2006, 01:54
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.

wysota
1st March 2006, 08:18
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.