定义“功能”我无法重构。但需要在测试类中使用。使用 Qt 4.8。以下代码返回 1,但预期为 2。
如何在测试类中使用 typedef 枚举?
#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)
};