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

Q_ENUMS and using declarations do not work together

    XMLWordPrintable

Details

    Description

      Consider the following class definition:

          #include <QObject>
      
          enum class FOO { BAR };
      
          class Exported: public QObject {
              Q_OBJECT
      
          public:
              using QObject::QObject;
              using FOO = ::FOO;
              Q_ENUM(FOO)
          };
      

      Exported to the QML environment as it follows:

          qmlRegisterType<Exported>("Package", 1, 0, "Exported");
      

      We can't use the named constant as usual, that is:

          import Package 1.0
      
          // ...
      
          Exported.BAR
      

      On the other side, the following works fine:

          class Exported: public QObject {
              Q_OBJECT
      
          public:
              using QObject::QObject;
              enum class FOO { BAR };
              Q_ENUM(FOO)
          };
      

      As weel as this one:

          class Exported: public QObject {
              Q_OBJECT
      
          public:
              using QObject::QObject;
              enum class FOO;
              Q_ENUM(FOO)
              enum class FOO { BAR };
          };
      

      In other terms using declarations, even though they import a set of names into their declarative regions, are not treated as enum declarations.
      Documentations is misleading. If the issue can't be solved, the docs should be updated at least.

      Here is a question on SO related to the argument: http://stackoverflow.com/questions/40511980/q-enums-and-using-declarations-do-not-work-together

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            skypjack Michele Caini
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes