[Qt-interest] QVariant and user defined types
Justus Best
Just18 at gmx.de
Tue Jun 1 16:47:33 CEST 2010
Hi,
> You have to register the metatype with a call to qRegisterMetaType first. You
> shouldn't assign your own numbers. Most applications have user-defined
> metatypes registered, so there's a huge risk of clashing if you do it the way
> you wrote above.
>
Ok as the types are determined at runtime as I learnd from Dan Misburn
there will be no way for me to use a switch.
Maybe the cascading ifs I use at the moment are not that much harder to
read.
Thanks for your fast reply Justus
Am 01.06.2010 16:27, schrieb Dan Milburn:
> 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
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
More information about the Qt-interest-old
mailing list