Define of "function" I can't refactor. But need use in test class. Used Qt 4.8. The following code return 1, but expected 2.
How to use typedef enum in test class?
#include <QDebug>
#include <QObject>
#include <QMetaEnum>
typedef enum {
READ = 0x30,
AUTH = 0x40,
EJECT = 0x55
}__attribute__ ((packed)) function;
class test : public QObject
{
Q_OBJECT
public:
explicit test(QObject *parent = 0){
qDebug() << "Enums count=" << this->metaObject()->enumeratorCount();
qDebug() << "Functions=" << this->metaObject()->enumerator( this->metaObject()->indexOfEnumerator("function") ).keyCount();
qDebug() << "worked=" << this->metaObject()->enumerator( this->metaObject()->indexOfEnumerator("worked") ).keyCount();
}
Q_ENUMS(function)
enum worked{forexample};
Q_ENUMS(worked)
};
The
typedef
construct isn't necessary in C++ code, and that applies to enums outside of classes, too. But this isn't your problem; the enum has to be a member of aQObject
subclass to be used with the metaObject, as you already tested withenum worked
.More details: http://doc.qt.io/qt-4.8/qobject.html#Q_ENUMS