Qt has a powerfull introspection system. using QMetaObject can access to all data generated for MOC.
enums, properties, signals and slots declared in the class
the follow code get the the values of the enum ViewportAnchorin the class QGraphicsView
#include <QApplication>
#include <QMetaEnum>
#include <QMetaType>
#include <QGraphicsView>
#include <qDebug>
int main(int argc, char *argv[])
{
const QMetaObject * dataObject
= examples
->metaObject
();
//get the index of the "ViewportAnchor" enum in the dataObject
int indexViewport = dataObject->indexOfEnumerator("ViewportAnchor");
QMetaEnum enumData
= dataObject
->enumerator
(indexViewport
);
qDebug() << "Values of enum " << enumData.name();
for (int x = 0; x < enumData.keyCount(); ++x)
qDebug() << enumData.valueToKey(x);
return a.exec();
}
#include <QApplication>
#include <QMetaEnum>
#include <QMetaType>
#include <QGraphicsView>
#include <qDebug>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QGraphicsView * examples = new QGraphicsView;
const QMetaObject * dataObject = examples->metaObject();
//get the index of the "ViewportAnchor" enum in the dataObject
int indexViewport = dataObject->indexOfEnumerator("ViewportAnchor");
QMetaEnum enumData = dataObject->enumerator(indexViewport);
qDebug() << "Values of enum " << enumData.name();
for (int x = 0; x < enumData.keyCount(); ++x)
qDebug() << enumData.valueToKey(x);
return a.exec();
}
To copy to clipboard, switch view to plain text mode
for use this system in our class in necesary use the macro Q_ENUMS.
{
Q_OBJECT
Q_ENUMS(Priority)
public:
~MyClass();
enum Priority { High, Low, VeryHigh, VeryLow };
void setPriority(Priority priority);
Priority priority() const;
};
class MyClass : public QObject
{
Q_OBJECT
Q_ENUMS(Priority)
public:
MyClass(QObject *parent = 0);
~MyClass();
enum Priority { High, Low, VeryHigh, VeryLow };
void setPriority(Priority priority);
Priority priority() const;
};
To copy to clipboard, switch view to plain text mode
the previus post resolved the question,
i read wrong the question. but i hope someone find the post useful.
sorry my poor english
Bookmarks