Convert custom type to QVariant

293 Views Asked by At

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.

1

There are 1 best solutions below

0
Dean Johnson On BEST ANSWER

For QVariant to store a custom type, you need the type to be registered with the qt meta object system.

  1. Q_ENUM or Q_ENUM_NS in the header of the type
  2. qRegisterMetaType<MyType>() called sometime before you try to use the type with QVariant (usually setup somewhere that is called when your app starts)