c++qtenumsqmetaobjectqmetatype

Is Qt's meta system really that tedious?


I would like to use Qt's reflection mechanism since C++ lacks of this feature. It seems to work, but calling all the macros and helper functions is very tedious. For example to register an enum as a proper meta type I had to go through all the following steps:

  1. Declare an enum inside of a wrapper class that contains the Q_GADGET macro.
  2. Register the enum using the Q_ENUM macro just after that.
  3. Register the class containing the enum: Q_DECLARE_METATYPE(MyClass)
  4. Call qRegisterMetaType<..>() for the type of the wrapping class and for each declared enum.

Now I know that some of the steps can be omitted if part of the full functionality is not required. But that is not what I am looking for, I need to use enums within signals and I need to be able to get the the meta method of a signal and query it for it's parameters type.

But still I can't help thinking that there must be a better/simpler way to do this.


Solution

  • Unfortunately, you can't do less than that.

    Depending on what exactly you need to do you need a subset of all of this.