Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-118527

Incorrect "Invalid QML element name" error for Q_GADGET enums

    XMLWordPrintable

Details

    Description

      One method of exposing C++ enums to QML has been to use Q_GADGET in combination with qmlRegisterUncreatableType, e.g.:

      class MyStatus
      {
          Q_GADGET
      public:
          enum Value
          {
              Off,
              On,
              Failed
          };
          Q_ENUM(Value)
      ...

      This works fine with no errors in Qt 5.15.2.
      However, when using Qt 6.4.3, it seems to work but you get the following runtime error in the console:
      qt.qml.typeregistration: Invalid QML element name "MyStatus"; value type names should begin with a lowercase letter.

      It is normal/recommended for enums and their elements to start with an upper-case letter.

      Also, is there a new/recommended way of using an enum in both C++ and QML?

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qtqmlteam Qt Qml Team User
            adam_price Adam Price
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes