@mrjj and @raven-worx , thanks for the replies! What I've gathered from this (and other posts) is: you can't use a Q_ENUM outside of QObject or a Q_GADGET macro. So in order to do what I wanted I need to change the code like this:
#ifndef EXAMPLE_H
#define EXAMPLE_H
#include <QObject>
struct Player {
Q_GADGET
public:
enum class CarType {
NO_CAR = 0,
SLOW_CAR,
FAST_CAR,
HYPER_CAR
}; Q_ENUM(CarType)
Q_PROPERTY(Player player READ getPlayer)
Q_PROPERTY(float m_speed READ getSpeed)
Q_PROPERTY(CarType m_carType READ getCarType)
Player getPlayer() { return *this;}
float getSpeed() {return m_speed;}
CarType getCarType() { return m_carType;}
public:
CarType m_carType;
float m_speed;
}; Q_DECLARE_METATYPE(Player)
#endif
#include <QCoreApplication>
#include <iostream>
#include <QMetaObject>
#include "example.h"
#include <QDebug>
#include <QMetaProperty>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
qRegisterMetaType<Player>();
const QMetaObject* metaObject = &Player::staticMetaObject;
qInfo() << "Number of enums is: " << metaObject->enumeratorCount();
const QMetaEnum metaEnum = metaObject->enumerator(0);
qInfo() << "Enum name: " << metaEnum.enumName();
int i = 0;
for(i = 0; i < metaEnum.keyCount(); i++)
qInfo() << "Enum key: " << metaEnum.key(i) << "; Value: " << metaEnum.value(i);
return a.exec();
}
Thanks for your time!