[Qt-interest] How to use QVariant with enum?

Kamil Klimek naresh at tlen.pl
Sat Dec 25 18:35:23 CET 2010


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


More information about the Qt-interest-old mailing list