PDA

View Full Version : How to make a general purpose storage class?



khikho
3rd February 2009, 22:10
Dear

I am hoping to create a multi-purpose class that store thing. Does any have an idea how to implement this?

I am thinking of using a QMap< QString key, "a non type thing pointer" > map that let me store any thing with key and later retrieve it using the key. however, the value must be of a general-non-type type like the QVariant such that I can cast it back to my type and use. But I don't know how to use Qvariant for this purpose.

Had anyone toy around with this idea or have recommended solution? Is there a way? Is it even possible?

thanks in advance
khikho

wysota
3rd February 2009, 23:16
How about just using QVariantMap? You can store any type you want in QVariant. Read about Q_DECLARE_METATYPE.