Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Enums in Qt 6.2.* How?
Qt 6.12 LTS is out! See what's new in the release blog

Enums in Qt 6.2.* How?

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 1.1k Views
  • 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.
  • B Offline
    B Offline
    bogong
    wrote on last edited by bogong
    #1

    Hello!
    Trying to work previously developed code base with Qt 6.2.8 and got stack with Enums declaring for QML and Qvariant. There are:

    // Namespace
    namespace ARB {
    
    // Class definitions
    class EnumClass : public QObject {
    
    	Q_OBJECT
    
    	public:
    
    		enum class Status: int {
    
    			Error = 0,
    			Ok = 1,
    			Existed = 2,
    			NotExisted = 3
    		};
    		Q_ENUM(Status)
    };
    
    } // namespace ARB
    
    Q_DECLARE_METATYPE(ARB::EnumClass::Status)
    

    In *.cpp registering class:

    qRegisterMetaType<ARB::EnumClass::Status>("Status");
    qmlRegisterType<ARB::EnumClass::Status>("Enums", 1, 0, "Status");
    

    In QML file:

    import Enums 1.0
    

    What is missing by me? For now there are error in passing enum from QML to C++:

    ("Status", QVariant(Invalid))
    

    It's even marked in Qt Creator editor in QML (bold font). But not working in reality.

    1 Reply Last reply
    0
    • B Offline
      B Offline
      bogong
      wrote on last edited by
      #2

      Issue solved. Solution found in my own examples. Got everything forgotten about enums in Qt. There were everything wrong with naming of QML types and registering ...
      This example showing working example for Qt 6.2.8

      1 Reply Last reply
      1
      • B bogong has marked this topic as solved on

      • Login

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