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

Q_ENUMS doesn't register negative enums

    XMLWordPrintable

Details

    Description

      A negative enum defined in a C++ class translates as 'undefined' in QML.

      #ifndef TEST_H
      #define TEST_H
      
      #include <QtCore>
      
      class Test : public QObject
      {
          Q_OBJECT
      public:
          enum MyEnum {
              Foo = -1,
              Foo0 = 0,
              Foo1 = 1
          };
      
          Q_ENUMS(MyEnum)
      };
      
      #endif // TEST_H
      #include <QtGui>
      #include <QtDeclarative>
      #include "test.h"
      
      int main(int argc, char **argv) {
          QApplication app(argc, argv);
      
          qmlRegisterType<Test>("mylib", 1, 0, "Test");
          QDeclarativeView v;
          v.setSource(QString("test.qml"));
          v.show();
      
          return app.exec();
      }
      
      import QtQuick 1.0
      import mylib 1.0
      
      Rectangle {
          width: 100
          height: 62
      
          Component.onCompleted: {
              console.log("Enum: " + Test.Foo + " " + Test.Foo0 + " " + Test.Foo1);
          }
      }
      

      And the output is: Enum: undefined 0 1
      while it should be: Enum: -1 0 1.

      Attachments

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

        Activity

          People

            earthdomain Earth Domain (Inactive)
            coyotte508 coyotte508
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes