Hi everyone,
I am trying to get the string value of enum.
My classa.h:
{
Q_OBJECT
Q_ENUMS(errType)
public:
enum errType{SUCCESS,ERROR};
classA();
};
class classA : public QObject
{
Q_OBJECT
Q_ENUMS(errType)
public:
enum errType{SUCCESS,ERROR};
classA();
};
To copy to clipboard, switch view to plain text mode
main.cpp:
int index = classA::staticMetaObject.indexOfEnumerator("errType");
qDebug()<<index;
qDebug() << "Available enums in" << mo.className() << ":" << mo.enumeratorCount();
int index = classA::staticMetaObject.indexOfEnumerator("errType");
qDebug()<<index;
const QMetaObject & mo = classA::staticMetaObject;
qDebug() << "Available enums in" << mo.className() << ":" << mo.enumeratorCount();
To copy to clipboard, switch view to plain text mode
If i will compile with Q_OBJECT then undefined reference to classA::staticMetaObject and undefined reference to vtable for classA built error will come.
If i will compile without Q_OBJECT then compilation will be fine.But index will be -1 and enumetator count will be 0.
Please tell how i will register the enum and get the string value of enum.
Thanks.
Bookmarks