Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Accessing Q_ENUMS in QML
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Accessing Q_ENUMS in QML

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 1.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Elegant
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • E Offline
      E Offline
      Elegant
      wrote on last edited by
      #2

      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@

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved