why my code does not read my specified keys from my enum.
The code itself compiles fine and the program runs without any runtime errors.
Header file with the enum:
#include <QMetaEnum>
class Planet: public QObject
{
public:
enum PlanetTypes
{
Barren,Gas,Ice,Lava,Oceanic,Plasma,Storm,Temperate
};Q_ENUM(PlanetTypes)
Planet();
//some getters and setters for my private membervariables
}
And here is the method from datamodel where I read the enum using QMetaEnum
QStringList DataModel::getPlanetTypes()
{
QStringList PlanetTypesList;
Planet p;
const QMetaObject* metaObj = p.metaObject();
QMetaEnum e = metaObj->enumerator(metaObj->indexOfEnumerator("PlanetTypes"));
for(int i=0; i<e.keyCount();i++)
{
PlanetTypesList.append(e.key(i));
}
return PlanetTypesList;
}
Debug shows that the QMetaEnum e does not find the Enumerator. The for loop never runs.
But there is no compiler - or runtime error.
I have actually no clue why it does not find the enum or its keys.