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. Q_PROPERTY and enum
Qt 6.11 is out! See what's new in the release blog

Q_PROPERTY and enum

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 6.2k 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.
  • Gianluca86G Offline
    Gianluca86G Offline
    Gianluca86
    wrote on last edited by
    #1

    Hello everyone, I have a problem with enum and Q_PROPERTY.
    I created an enum in a class:

    class ClassA 
    {
    Q_OBJECT
       public:
          enum Enum_Test
          {
              eTestA,
              eTestB
          }
        ...
    }
    

    In another class I call this enum in the properties:

    #include "ClassA.h"
    class ClassB
    {
        Q_OBJECT
        Q_ENUMS(ClassA::Enum_Test)
    
        Q_PROPERTY(ClassA::Enum_Test enumTest READ GetEnumTest WRITE SetEnumTest )
    ...
    }
    

    Despite using the Q_ENUMS gives me the following error:
    QMetaProperty::read: Unable to handle unregistered datatype 'ClassA::Enum_Test' for property 'ClassB::enumtest'

    I can not understand where I'm wrong.
    Unfortunately I am obliged to have the Enum in different class from the properties.
    Thanks

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2
      • Q_ENUMS is deprecated, use Q_ENUM, see https://woboq.com/blog/q_enum.html
      • depending on the usage you might also have to register the enum metatype: http://doc.qt.io/qt-5/qmetatype.html#qRegisterMetaType-1

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      1
      • Gianluca86G Offline
        Gianluca86G Offline
        Gianluca86
        wrote on last edited by
        #3

        Thanks, now work fine.
        I use Q_ENUM and I moved it in ClassA

        class ClassA 
        {
        Q_OBJECT
           public:
              enum Enum_Test
              {
                  eTestA,
                  eTestB
              }
            Q_ENUM(Enum_Test)
            ...
        }
        
        #include "ClassA.h"
        class ClassB
        {
            Q_OBJECT
        
            Q_PROPERTY(ClassA::Enum_Test enumTest READ GetEnumTest WRITE SetEnumTest )
        ...
        }
        

        thanks

        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