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. QML autocomplete / intellisense doesn't work for namespace enums
Forum Updated to NodeBB v4.3 + New Features

QML autocomplete / intellisense doesn't work for namespace enums

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 3 Posters 1.0k 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.
  • A Offline
    A Offline
    aatwo
    wrote on last edited by
    #1

    Hi all. Running Qt Creator 4.14.0 with a Qt 6.0.1 MSVC 2019 x64 toolchain.

    I have a namespace containing multiple enums which I want to be accesible to my QML. This is easy enough as the following example demonstrates:

    // testnamespace.h
    namespace TestNamespace
    {
        Q_NAMESPACE
    
        enum class TestEnum {
    
            TestEnum_option1,
            TestEnum_option2,
            TestEnum_option3
        };
        Q_ENUMS(TestEnum)
    }
    
    // main.cpp
    int main(int argc, char *argv[])
    {
        qmlRegisterUncreatableMetaObject(TestNamespace::staticMetaObject, "My.Company", 1, 0, "TestNamespace",  "Error: namespace not creatable");
        
        ...
    
    // main.qml
    import QtQuick 2.15
    import QtQuick.Window 2.15
    import My.Company 1.0
    
    Window {
        width: 640
        height: 480
        visible: true
        title: TestNamespace.TestEnum_option3
    }
    

    The problem is that while it will autocomplete the namespace in the QML file, there is no autocomplete for any of the namespace enum values.

    If instead the enum is placed into a QObject derived class and the class type is registered in the same way using qmlRegisterType() then the QML editor provides autocomplete for the enum values, but I don't really see this as a good solution for a number of reasons.

    So I guess the question is, is there any intent to resolve this in the future? Or is there a workaround that anyone knows of that can be used to get the autocomplete working for the namespace enum values?

    raven-worxR 1 Reply Last reply
    0
    • A aatwo

      Hi all. Running Qt Creator 4.14.0 with a Qt 6.0.1 MSVC 2019 x64 toolchain.

      I have a namespace containing multiple enums which I want to be accesible to my QML. This is easy enough as the following example demonstrates:

      // testnamespace.h
      namespace TestNamespace
      {
          Q_NAMESPACE
      
          enum class TestEnum {
      
              TestEnum_option1,
              TestEnum_option2,
              TestEnum_option3
          };
          Q_ENUMS(TestEnum)
      }
      
      // main.cpp
      int main(int argc, char *argv[])
      {
          qmlRegisterUncreatableMetaObject(TestNamespace::staticMetaObject, "My.Company", 1, 0, "TestNamespace",  "Error: namespace not creatable");
          
          ...
      
      // main.qml
      import QtQuick 2.15
      import QtQuick.Window 2.15
      import My.Company 1.0
      
      Window {
          width: 640
          height: 480
          visible: true
          title: TestNamespace.TestEnum_option3
      }
      

      The problem is that while it will autocomplete the namespace in the QML file, there is no autocomplete for any of the namespace enum values.

      If instead the enum is placed into a QObject derived class and the class type is registered in the same way using qmlRegisterType() then the QML editor provides autocomplete for the enum values, but I don't really see this as a good solution for a number of reasons.

      So I guess the question is, is there any intent to resolve this in the future? Or is there a workaround that anyone knows of that can be used to get the autocomplete working for the namespace enum values?

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @aatwo
      enums in a Q_NAMESPACE type should rather be registered with Q_ENUM_NS

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • A Offline
        A Offline
        aatwo
        wrote on last edited by
        #3

        In the above example using Q_ENUM_NS yeilds no change for me and there is still no intellisense / autocomplete in the QML editor for the enum values.

        J.HilkJ 1 Reply Last reply
        0
        • A aatwo

          In the above example using Q_ENUM_NS yeilds no change for me and there is still no intellisense / autocomplete in the QML editor for the enum values.

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @aatwo I have my QML enums in a basic c++ class with Q_GADGET macro as a lightweight alternative to Q_OBJECT (it does not require the class to be derived from QObject, too)

          If thats an alternative for you?


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          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