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

QML does not allow use of lower-case enum

    XMLWordPrintable

    Details

      Description

      Given some enums:

      
      #pragma once
      
      #include <QObject>
      
      struct MyEnums
      {
          Q_GADGET
      public:
          enum NumberEnum {
              Zero,
              One,
              Two,
              Three
          };
          Q_ENUM(NumberEnum)
      
          enum LetterEnum {
              aaa,
              bbb,
              ccc,
              ddd
          };
          Q_ENUM(LetterEnum)
      
          enum LetterEnum2 {
              Aaa,
              Bbb,
              Ccc,
              Ddd
          };
          Q_ENUM(LetterEnum2)
      
      };
      

      Registered as normal:

      #include <QGuiApplication>
      #include <QQuickView>
      
      #include "enumfile.h"
      
      int main(int argc, char** argv)
      {
          QGuiApplication app(argc, argv);
      
          qmlRegisterUncreatableType<MyEnums>("MyLib", 1, 0, "MyEnums", "MyEnums can not be instantiated");
      
          QQuickView view;
          view.setSource(QUrl("main.qml"));
          view.show();
      
          return app.exec();
      }
      

      Allowed use is inconsistent:

      import QtQuick 2.3
      import MyLib 1.0
      
      Item
      {
          width: 400
          height: 400
      
          QtObject {
              id: theObject
              property int enumValue: MyEnums.ccc
          }
      
          Text {
              anchors.centerIn: parent
              text: {
                  return "Enum MyEnums.Two is " + MyEnums.Two +
                      "\nEnum MyEnums.aaa is " + MyEnums.ccc +
                      "\nEnum MyEnums.Ccc is " + MyEnums.Ccc +
                      "\ntheObject.enumValue is " + theObject.enumValue
              }
          }
      }
      

      shows

      Enum MyEnums.Two is 2
      Enum MyEnums.aaa is undefined
      Enum MyEnums.Ccc is 2
      theObject.enumValue is 2
      

      Existing code can contain enums which start with a lower-case prefix.

        Attachments

          Issue Links

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

            Activity

              People

              Assignee:
              tmcguire Thomas McGuire
              Reporter:
              ske Steve
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Gerrit Reviews

                  There are no open Gerrit changes