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.
CodePudding user response:
For QVariant to store a custom type, you need the type to be registered with the qt meta object system.
Q_ENUM
orQ_ENUM_NS
in the header of the typeqRegisterMetaType<MyType>()
called sometime before you try to use the type with QVariant (usually setup somewhere that is called when your app starts)