I have delegate component in a separate qml file, in which I'd like to have a property which is an enum class type coming from a c++ QObject. Is this possible?
Here is a Minimum (non)Working Example:
card.h
#include <QObject>
class Card : public QObject
{
Q_OBJECT
public:
explicit Card(QObject *parent = 0);
enum class InGameState {
IDLE,
FLIPPED,
HIDDEN
};
Q_ENUM(InGameState)
private:
InGameState mState;
};
Q_DECLARE_METATYPE(Card::InGameState)
main.cpp
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include "card.h"
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
qmlRegisterType<Card::InGameState>("com.memorygame.ingamestate", 1, 0, "InGameState");
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}
testcard.qml
import QtQuick 2.0
import com.memorygame.ingamestate 1.0
Item {
property InGameState state
Rectangle {
id: dummy
width: 10
}
}
Compiler error I get:
D:\Programs\Qt\Qt5.7.0\5.7\mingw53_32\include\QtQml\qqml.h:89: error: 'staticMetaObject' is not a member of 'Card::InGameState' const char *className = T::staticMetaObject.className(); \
The enum class in not a QObject, that's why I get this error, right? But shouldn't Q_ENUM macro makes it available in the MetaSystem?
Could you please help me with this out? I could drop enum class, and change it to enum, and use an int property in qml, but I would like to use c++11 features.