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 use own enum with Q_INVOKABLE and namespace
Forum Updated to NodeBB v4.3 + New Features

How to use own enum with Q_INVOKABLE and namespace

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 1.6k Views 2 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.
  • B Offline
    B Offline
    Bernando
    wrote on 3 Feb 2018, 12:38 last edited by Bernando 2 Mar 2018, 12:40
    #1

    Hi,
    i will use this function from qml.

    Q_INVOKABLE bool startBackUp(SomeEnum i);
    

    The Enum is definied in *. h file:

    namespace MyNamespace
    {
        Q_NAMESPACE
      
        enum class SomeEnum {
            Foo,
            Bar
        };
        Q_ENUM_NS(SomeEnum)
    }
    
    I did the registration (```
    qmlRegisterUncreatableMetaObject(MyNamespace::staticMetaObject, ..."MyNamespace", 
    ```)
    

    Im write the ```

    "import myImort 1.0"
    

    Is use the function in qml:

    Model.startBackUp( MyNamespace.Foo) // works not!
    console.log("MyEnums: " + MyNamespace.Foo + " " + MyNamespace.bar  ) // works: MyEnums: 0 1
    

    I get the Message: ```
    Error: Unknown method parameter type: MyNamespace.Foo

    it works fine if i using an Integer datatype: ```

    Q_INVOKABLE bool startBackUp(int i); // works
    Model.startBackUp( MyNamespace.Foo) // works
    
    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 3 Feb 2018, 22:37 last edited by
      #2

      Hi,

      Do you also call Q_DECLARE_METATYPE and qRegisterMetaType ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • B Offline
        B Offline
        Bernando
        wrote on 4 Feb 2018, 12:09 last edited by Bernando 2 Apr 2018, 12:09
        #3

        Yes i do.

        The console.log works fine. And also with Integer.

        Only here I get the errror message:

        Q_INVOKABLE bool startBackUp(SomeEnum i);
        ```  //Error: Unknown method parameter type: MyNamespace.Foo
        1 Reply Last reply
        0

        1/3

        3 Feb 2018, 12:38

        • Login

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