[Qt-interest] ***SPAM*** Re: How to deal with pointers for a QDataStream?

Ramesh ramesh.bs at robosoftin.com
Wed Apr 21 14:56:16 CEST 2010


Hi,

The best way to store the structure item using the datastream is,
You need to override the "<<" ">>" operators, pass the refrence, write the
each member at a time..

And the way you read must match to the way you write to file...


-----Original Message-----
From: qt-interest-bounces at trolltech.com
[mailto:qt-interest-bounces at trolltech.com] On Behalf Of Andre Somers
Sent: Monday, April 19, 2010 6:32 PM
To: qt-interest at trolltech.com
Subject: ***SPAM*** Re: [Qt-interest] How to deal with pointers for a
QDataStream?

On 19-4-2010 14:41, Oliver Heins wrote:
> I have a data structure which holds some pointers:
>
> class Token
> {
> public:
>      enum Type { Space, Paragraph, Kern, Char, Format, Note, End };
>      enum SubType { Bold, Italic,
>                     Header1, Header2, Header3, Header4, Header5, Header6,
>                     Itemize, Enumerate, Description, Item,
>                     Note1, Note2, Note3, Note4, Note5 };
>
>      [...]
>
>      Type type;
>      SubType subType;
>      QChar chr;
>      Token *parent;
>      QLinkedList<Token *>  children;
>      Token *partner;
> };
>
> As saving pointers directly to a QDataStream will obviously not work,
> what would be a good strategy to save the structure?
>
>

One way is to give each item you need to store a pointer to an ID that
is unique for the file (if such a thing is not already there), and store
these ID's instead of the pointers to the objects. On loading, you can
reconstruct the pointers by using the ID's to lookup the addresses from
some (temporary?) data structure such as a QHash<int, Token*> that you
keep around at loading time.

André

_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest


-----------------------------------------------
Robosoft Technologies - Come home to Technology

Disclaimer: This email may contain confidential material. If you were not an intended recipient, please notify the sender and delete all copies. Emails to and from our network may be logged and monitored. This email and its attachments are scanned for virus by our scanners and are believed to be safe. However, no warranty is given that this email is free of malicious content or virus.



More information about the Qt-interest-old mailing list