Qt-fy existing enum to use with Qt metadata

送分小仙女□ 提交于 2019-12-13 14:41:09

问题


Let's assume I have an existing enum X { A, B } and want to use it with Qt metadata such as QMetaObject / QMetaEnum.

QMetaObject meta = FsxSimConnectQtfier::staticMetaObject;
for (int i=0; i < meta.enumeratorCount(); ++i) {
    QMetaEnum m = meta.enumerator(i);
}

If I define my enum within a Q_OBJECT class, all is fine, i.e. I can retrieve MyEnum by the metadata system. But how can I make X available for the metadata system?

class FsxSimConnectQtfier : public QObject
{
    Q_OBJECT
    Q_ENUMS(MyEnum) 
    Q_ENUMS(X) // not working
public:
    explicit FsxSimConnectQtfier(QObject *parent = 0);
    enum MyEnum { G1, G2 };
    // how can I make enum X available for the metadata system
    // I have tried typedef, but did not work
    static const QString simConnectExceptionToString(const unsigned int id);
};
  1. This is a follow up of: Qt: No metadata by meta.enumeratorCount() for enum in Q_OBJECT, why?
  2. Motivation: The real enum X contains many exception codes, and I want to use the metadata system to fetch the original descriptive text, pretty much as here. The original enum is not(!) an Q_OBJECT.

来源:https://stackoverflow.com/questions/11690684/qt-fy-existing-enum-to-use-with-qt-metadata

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!