[Qt-interest] How to use QVariant with enum?
Robert Escott
robert at binarylogic.co.za
Sun Dec 26 05:27:04 CET 2010
Look up Q_DECLARE_METATYPE in the documentation.
-----Original Message-----
From: qt-interest-bounces+robert=binarylogic.co.za at qt.nokia.com [mailto:qt-interest-bounces+robert=binarylogic.co.za at qt.nokia.com] On Behalf Of Kamil Klimek
Sent: 25 December 2010 19:35
To: mdillist Qt
Subject: Re: [Qt-interest] How to use QVariant with enum?
Wiadomość napisana przez 程梁 w dniu 2010-12-25, o godz. 17:47:
> I want to use an enum as the user data in QComboBox, say
> MyClass::MyEnum. But when I tried to get this data using
> QComboBox::itemData(UserRole), I cannot convert it to this enum. I
> read the docs and add Q_ENUMS(MyEnum) in myclass.h, but it doesn't
> work. The enum is only a util class's data, there is no need to set it
> as a property, how should I do if I want to convert QVariant to custom
> enum?
>
> --
> Cheng Liang
> from: chengliang.soft at gmail.com
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
(YourEnum)yourVariant.toInt();
should do the work
_______________________________________________
Qt-interest mailing list
Qt-interest at qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list