[Qt-interest] QVariant and user defined types
Thiago Macieira
thiago at kde.org
Tue Jun 1 15:28:22 CEST 2010
Em Terça-feira 01 Junho 2010, às 13:52:07, Justus Best escreveu:
> 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 ?
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.
QVariant::type() will return UserType if it's a user type. However,
QVariant::userType() returns the actual ID.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Senior Product Manager - Nokia, Qt Development Frameworks
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100601/b818488f/attachment.bin
More information about the Qt-interest-old
mailing list