[Solved]Iterate over enum, using QMetaEnum
-
Hi,
QMetaEnum is used in conjunction with Q_ENUMS. Is it the case of yours ?
-
After SGaist's hint I ended up with a possible solution
I first define on my class
@class SomeClass : public QObject
{
Q_OBJECT
Q_ENUMS(Letters)public:
enum Letters
{ A, B };...@
then I can simply do
@QMetaObject meta = SomeClass::staticMetaObject;
QMetaEnum tmpObj = meta.enumerator(0);
for (int i = 0; i < tmpObj.keyCount(); i++)
{
qDebug() << tmpObj.key(i);
}@If there are any better ways i'd be glad to know.
-
It depends on you use case. You can also have a simple function with a switch that returns a string