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. Enumerations in uncreatable types with lowercase name
Qt 6.11 is out! See what's new in the release blog

Enumerations in uncreatable types with lowercase name

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 2 Posters 1.4k 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.
  • beeckscheB Offline
    beeckscheB Offline
    beecksche
    wrote on last edited by
    #1

    Hi,
    i'm not able to acces my enumerations of an uncreatable type if the name is lowercase.

    myclass.h

    class MyClass {
     Q_GADGET
    public:
     enum MyEnum { Value1, Value2 };
     Q_ENUM(MyEnum)
    }
    

    main.cpp

    int main(int argc, char *argv[])
    {
     qRegisterUncreatableType<MyClass>("my.company", 1, 0, "MyClass"); // qt.qml.typeregistration: Invalid QML element name "MyClass"; value type names should begin with a lowercase letter
     qRegisterUncreatableType<MyClass>("my.company", 1, 0, "myClass");
    
     QQmlApplicationEngine engine;
     engine.load(QUrl(QLatin1String("qrc:/main.qml")));
    }
    

    main.qml

    import QtQuick 2.15
    import QtQuick.Window 2.15
    import QtQuick.Controls 2.15
    
    import my.company1.0
    
    ApplicationWindow {
        Component.onCompleted: {
            console.log(MyClass.Value1) // works
            console.log(myClass.Value1) // ReferenceError: myClass is not defined
        }
    }
    
    GrecKoG 1 Reply Last reply
    0
    • beeckscheB beecksche

      Hi,
      i'm not able to acces my enumerations of an uncreatable type if the name is lowercase.

      myclass.h

      class MyClass {
       Q_GADGET
      public:
       enum MyEnum { Value1, Value2 };
       Q_ENUM(MyEnum)
      }
      

      main.cpp

      int main(int argc, char *argv[])
      {
       qRegisterUncreatableType<MyClass>("my.company", 1, 0, "MyClass"); // qt.qml.typeregistration: Invalid QML element name "MyClass"; value type names should begin with a lowercase letter
       qRegisterUncreatableType<MyClass>("my.company", 1, 0, "myClass");
      
       QQmlApplicationEngine engine;
       engine.load(QUrl(QLatin1String("qrc:/main.qml")));
      }
      

      main.qml

      import QtQuick 2.15
      import QtQuick.Window 2.15
      import QtQuick.Controls 2.15
      
      import my.company1.0
      
      ApplicationWindow {
          Component.onCompleted: {
              console.log(MyClass.Value1) // works
              console.log(myClass.Value1) // ReferenceError: myClass is not defined
          }
      }
      
      GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #2

      This is a bit awkward for the moment and I'm not convinced by the way it should be done currently.
      You can add pragma ValueTypeBehavior: Addressable at the top of a QML file to be able to refer to value types and then your latter snippet would work.
      For reference (the last comment by Ulf): https://bugreports.qt.io/browse/QTBUG-88008?focusedId=712036&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-712036

      beeckscheB 1 Reply Last reply
      2
      • GrecKoG GrecKo

        This is a bit awkward for the moment and I'm not convinced by the way it should be done currently.
        You can add pragma ValueTypeBehavior: Addressable at the top of a QML file to be able to refer to value types and then your latter snippet would work.
        For reference (the last comment by Ulf): https://bugreports.qt.io/browse/QTBUG-88008?focusedId=712036&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-712036

        beeckscheB Offline
        beeckscheB Offline
        beecksche
        wrote on last edited by beecksche
        #3

        @GrecKo said in Enumerations in uncreatable types with lowercase name:

        pragma ValueTypeBehavior: Addressable

        leads to

        error: Unknown value type behavior 'Addressable' in pragma
        

        I'm working with Qt6.5: only Copy and Reference values for the ValueTypeBehavior pragma are experimental options. And both do not work.

        GrecKoG 1 Reply Last reply
        0
        • beeckscheB beecksche

          @GrecKo said in Enumerations in uncreatable types with lowercase name:

          pragma ValueTypeBehavior: Addressable

          leads to

          error: Unknown value type behavior 'Addressable' in pragma
          

          I'm working with Qt6.5: only Copy and Reference values for the ValueTypeBehavior pragma are experimental options. And both do not work.

          GrecKoG Offline
          GrecKoG Offline
          GrecKo
          Qt Champions 2018
          wrote on last edited by
          #4

          This pragma was added in Qt 6.6 : https://doc.qt.io/qt-6/qtqml-documents-definetypes.html#valuetypebehavior

          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