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

Allow using enums as properties in QML

    XMLWordPrintable

Details

    Description

      It seems that enums which are exported from C++ can not be used as properties in QML.

      Consider the following example:

      C++:

      class Bar : public QObject
      {
        Q_OBJECT
        QML_ELEMENT
        public:
          enum Weather { Raining, Sunny, Cloudy }
          Q_ENUM(Weather)
      };
      

      QML:

      Item {
        property Bar.Weather weather: Bar.Sunny
      }
      

      This doesn't work because we don't allow enums to be used as types in QML.

      It would be nice if exported enums just worked as properties. A workaround is to use "int" as the property type instead.

      Attachments

        Issue Links

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

          Activity

            People

              qtqmlteam Qt Qml Team User
              tmcguire Thomas McGuire
              Votes:
              29 Vote for this issue
              Watchers:
              34 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes