[Qt-interest] QVariant and user defined types
Dan Milburn
danmilburn at clara.co.uk
Tue Jun 1 16:27:44 CEST 2010
Justus Best wrote:
> Hi,
>
> I currenty stuck a little while trying to add some of my classes to
> QVariant.
> My problem is that I can't find a way to put my Types in an enum and use
> them in a switch case with QVariant::userType().
> I tried with an enum like :
> enum MyTypes { Type1 = QVariant::UserType, Type2, Type3, Type4, Type5 };
> But this doesn't correspond with the TypeIds I get if I call
> QVariant::userType().
>
> So is there any possibility to use QVariant with user definded types in
> a switch statment ?
In short, no. The user type ids are not available at compile time so
you can't use them in a switch statement. You would need to map from
the qMetaTypeId of the registered type to the values in your enum in
some way.
Dan
More information about the Qt-interest-old
mailing list