Qt: No metadata by meta.enumeratorCount() for enum in Q_OBJECT, why?

后端 未结 1 858
渐次进展
渐次进展 2021-01-23 10:42

I have the following class, where I try to obtain some metadata of an enum MyEnum. However, when looping over meta.enumeratorCount() its count is alway

1条回答
  •  隐瞒了意图╮
    2021-01-23 11:39

    You need to register the enum with the metadata system using the Q_ENUMS() macro:

    class FsxSimConnectQtfier : public QObject
    {
        Q_OBJECT
        Q_ENUMS(MyEnum)  // <--- 
    
    public:
        explicit FsxSimConnectQtfier(QObject *parent = 0);
        enum MyEnum { G1, G2 };
        static const QString simConnectExceptionToString(const unsigned int id);
    };
    

    0 讨论(0)
提交回复
热议问题