[SOLVED] Accessing Q_ENUMS in QML
-
Quick note: I have checked other topics and could not identify the correct syntax.
@
class Pet : public QObject
{
Q_OBJECT
Q_ENUMS(PetStatus)
public:
enum PetStatus { Stun, Rooted };
...
}@@qmlRegisterType<Pet>(); //In other class.@
This class is used in a QList within PetTeam which is used in a QList within PetStage. The two higher classes do not have enums. The PetStage object alone is sent to the QML and from there everything else is accessed from within QML as it is aware of the hierarchy.
@petStage.team[1].pet[2].name //Works in QML@
The problem I'm having is I want to use the enum in QML and I am unaware of the correct syntax to use in QML so that
@
console.log(X.Rooted) //prints 1; I thought Pet.Rooted would work but it does not@functions correctly.
-
Solution is to to create another qmlRegisterType
@qmlRegisterType<Pet>("PetStatus", 1, 0, "PetStatus");@
from there you would import into the QMLscript
@import PetStatus 1.0@
and call it from QML using
@PetStatus.Rooted //Or whatever naming convention you used for your elements@