Sounds like a job for QDataStream. Pay attention to the Detailed Description.
Sounds like a job for QDataStream. Pay attention to the Detailed Description.
J-P Nurmi
Hi,
Cheers for the reply.
I've had a look at QDataStream.
But that ony seems to support native types (int, char, etc)
How can u use it to store something like a QString or an instance of my own class?
Cheers
I told you to pay attention to the detailed description..
You can write QDataStream operators for your class:Each item written to the stream is written in a predefined binary format that varies depending on the item's type. Supported Qt types include QBrush, QColor, QDateTime, QFont, QPixmap, QString, QVariant and many others. For the complete list of all Qt types supporting data streaming see the Format of the QDataStream operators.
Qt Code:
QDataStream& operator << (QDataStream& stream, const SomeClass& some) { stream << ... return stream; } QDataStream& operator >> (QDataStream& stream, SomeClass& some) { ... stream >> .. return stream; }To copy to clipboard, switch view to plain text mode
J-P Nurmi
Overloaded operators << and >> for other data types are defined in the data class itself, not in the QDataStream class. This is better for the extensibility of the QDataStream class (in other words, you don't need to modify the QDataStream class itself to extend its supported types).
That means you have to look in each class you want to serialize if the functions like that exist :
QDataStream & operator<< ( QDataStream & stream, const QString & string )
QDataStream & operator>> ( QDataStream & stream, QString & string )
EDIT: In addition, this url shows you all data serializable with QDataStream, given the Qt framework.
For you own needs, you will probably define you own overloaded operators for you specific data class.
Bookmarks