This documentation states
If you want to register an enumeration declared in another class, the enumeration must be fully qualified with the name of the class that defines it. In addition, the class that defines the enumeration must inherit a QObject, and also declare the enumeration using Q_ENUMS ().
However, I cannot do this work in the following example.
Grade A:
#ifndef CLASSA_H #define CLASSA_H #include <classb.h> class ClassA : public QObject { Q_OBJECT Q_ENUMS(ClassB::TestEnum) public: explicit ClassA(QObject *parent = 0) : QObject(parent) { const QMetaObject *metaObj = this->metaObject(); qDebug() << metaObj->enumeratorCount(); } }; #endif // CLASSA_H
ClassB:
#ifndef CLASSB_H #define CLASSB_H #include <QDebug> #include <QMetaEnum> #include <QObject> class ClassB : public QObject { Q_OBJECT Q_ENUMS(TestEnum) public: enum TestEnum { A, B, C }; explicit ClassB(QObject *parent = 0) : QObject(parent) { const QMetaObject *metaObj = this->metaObject(); qDebug() << metaObj->enumeratorCount(); } }; #endif // CLASSB_H
home:
#include <classa.h> #include <classb.h> int main() { ClassA objectA; ClassB objectB; }
Expected Result:
1
1
Actual output:
0
1
source share