1

「関数」の定義がリファクタリングできません。ただし、テストクラスで使用する必要があります。Qt4.8を使用。次のコードは 1 を返しますが、予想されるのは 2 です。

テストクラスでtypedef enumを使用するには?

#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)
};
4

1 に答える 1

1

このtypedef構造は C++ コードでは必要ありません。これは、クラス外の列挙型にも当てはまります。しかし、これはあなたの問題ではありません。QObjectで既にテストしたように、enum は metaObject で使用されるサブクラスのメンバーである必要がありますenum worked

詳細: http://doc.qt.io/qt-4.8/qobject.html#Q_ENUMS

于 2016-02-24T16:43:21.993 に答える