Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to pass an enum from a c++ pure virtual class to qml?

How to pass an enum from a c++ pure virtual class to qml?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 1.3k 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.
  • C Offline
    C Offline
    c64zottel
    wrote on last edited by c64zottel
    #1

    I am desperately trying to pass an enum from C++ to qml.

    My class, with deviceType() as patient, looks as follows:

    enum InputDeviceType {
    	Undefined,
    	Keyboard,
    	Joystick,
    	Network,
    	Mouse,
    	Mouse3d
    };
    
    class InputDeviceConfiguratorGate : public QObject
    {
    	Q_OBJECT
    	Q_DISABLE_COPY(InputDeviceConfiguratorGate)
    	Q_PROPERTY( InputDeviceType deviceType READ deviceType )
    
    public:
    
    	explicit InputDeviceConfiguratorGate(QObject *parent = 0);
    	virtual ~InputDeviceConfiguratorGate() = 0;
    
    	virtual InputDeviceType deviceType();
    
            Q_INVOKABLE virtual QString         deviceId()     = 0;
    
    ...
    };
    

    The class is registered to qml via:

    qmlRegisterUncreatableType<InputDeviceConfiguratorGate>(
        "InputDeviceConfiguratorGate", 1, 0, "InputDeviceConfiguratorGate", "Not creatable in Qml." );
    

    I tried a lot of different combinations: putting the enum in a separate class, using Q_ENUM, Q_ENUMS (i know, deprecated), introduce Q_PROPERTY and remove Q_INVOKABLE and make the function not pure virtual.

    From the qml side, when trying to reference, I get the error:

    ReferenceError: InputDeviceType is not defined
    

    Which, so I believe, comes from the fact that InputDeviceConfiguratorGate is registered via qmlRegister Uncreatable Type.

    I know about the following bug: https://bugreports.qt.io/browse/QTBUG-58454, which made me remove Q_INVOKABLE.

    Are enums even possible in interfaces?

    E 1 Reply Last reply
    0
    • C c64zottel

      I am desperately trying to pass an enum from C++ to qml.

      My class, with deviceType() as patient, looks as follows:

      enum InputDeviceType {
      	Undefined,
      	Keyboard,
      	Joystick,
      	Network,
      	Mouse,
      	Mouse3d
      };
      
      class InputDeviceConfiguratorGate : public QObject
      {
      	Q_OBJECT
      	Q_DISABLE_COPY(InputDeviceConfiguratorGate)
      	Q_PROPERTY( InputDeviceType deviceType READ deviceType )
      
      public:
      
      	explicit InputDeviceConfiguratorGate(QObject *parent = 0);
      	virtual ~InputDeviceConfiguratorGate() = 0;
      
      	virtual InputDeviceType deviceType();
      
              Q_INVOKABLE virtual QString         deviceId()     = 0;
      
      ...
      };
      

      The class is registered to qml via:

      qmlRegisterUncreatableType<InputDeviceConfiguratorGate>(
          "InputDeviceConfiguratorGate", 1, 0, "InputDeviceConfiguratorGate", "Not creatable in Qml." );
      

      I tried a lot of different combinations: putting the enum in a separate class, using Q_ENUM, Q_ENUMS (i know, deprecated), introduce Q_PROPERTY and remove Q_INVOKABLE and make the function not pure virtual.

      From the qml side, when trying to reference, I get the error:

      ReferenceError: InputDeviceType is not defined
      

      Which, so I believe, comes from the fact that InputDeviceConfiguratorGate is registered via qmlRegister Uncreatable Type.

      I know about the following bug: https://bugreports.qt.io/browse/QTBUG-58454, which made me remove Q_INVOKABLE.

      Are enums even possible in interfaces?

      E Offline
      E Offline
      Eeli K
      wrote on last edited by
      #2

      @c64zottel said in How to pass an enum from a c++ pure virtual class to qml?:

      I tried a lot of different combinations: putting the enum in a separate class, using Q_ENUMS (i know, deprecated), introduce Q_PROPERTY and remove Q_INVOKABLE and make the function not pure virtual.

      Have you tried Q_ENUM? The one which is meant to replace Q_ENUMS?

      But I get among all the other errors:

      ReferenceError: InputDeviceType is not defined
      

      Is this a compiler error or what, and in what situation it comes? Please don't detach part of error messages from their contexts without even explaining where they come from, it doesn't help us at all.

      C 1 Reply Last reply
      0
      • E Eeli K

        @c64zottel said in How to pass an enum from a c++ pure virtual class to qml?:

        I tried a lot of different combinations: putting the enum in a separate class, using Q_ENUMS (i know, deprecated), introduce Q_PROPERTY and remove Q_INVOKABLE and make the function not pure virtual.

        Have you tried Q_ENUM? The one which is meant to replace Q_ENUMS?

        But I get among all the other errors:

        ReferenceError: InputDeviceType is not defined
        

        Is this a compiler error or what, and in what situation it comes? Please don't detach part of error messages from their contexts without even explaining where they come from, it doesn't help us at all.

        C Offline
        C Offline
        c64zottel
        wrote on last edited by
        #3

        @Eeli-K Sorry, I should have been more clear about that. I updated my post.

        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