I have my custom type:
enum class MyType : int {
TYPENAME1 = 0,
TYPENAME2 = 1,
TYPENAME3 = 2
};
I need to convert MyType
to QVariant
. I tried qDebug() << QVariant::fromValue(value)
but I received " "
instead of property value.
For QVariant to store a custom type, you need the type to be registered with the qt meta object system.
Q_ENUM
or Q_ENUM_NS
in the header of the type qRegisterMetaType<MyType>()
called sometime before you try to use the type with QVariant (usually setup somewhere that is called when your app starts)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.