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

RegisterEnumClassesUnscoped: Enum clashes with inherited classes

    XMLWordPrintable

Details

    • macOS
    • 8a2c182d5941a1d00ac9f7414d1508b7f959d6f3

    Description

      I noticed when compiling my project, which uses the QuickQanava library (see NodeItem.h and PortItem.h), multiple enum name clash warnings/errors are shown, since compiling with 5.12.

      I tried solving these, then I found out there was an option added "RegisterEnumClassesUnscoped" (in http://code.qt.io/cgit/qt/qtdeclarative.git/commit/?h=5.12&id=bb296168f426d7e646c0208427f25687f96e2693 by rakeller) , but it did not work in this case. Because of inherited (Qt) classes, still some enums are clashing. Don't know if this is a real bug, or it should just be implemented differently, but here it goes:

       

      Pseudo implementation:

       

      Class Base inherits QQuickItem

      • Defines an ENUM with members Left, Top, Right, Bottom
      • Tried setting Q_CLASSINFO("RegisterEnumClassesUnscoped", "false") here
      • Has to explicitly declare the enum with Q_DECLARE_METATYPE altough Q_ENUMS() is used?

      Class Child inherits Base

      • Contains a Q_PROPERTY of the ENUM type defined in Base
      • Has also set Q_CLASSINFO("RegisterEnumClassesUnscoped", "false")

      To note: I am not able to set Q_CLASSINFO("RegisterEnumClassesUnscoped", "false") for QQuickItem, as it is a Qt-specific (Is this even true?)

       

      Problem: Enum clash of Base with QQuickItem, because of e.g. defined ENUM Bottom clashes with TransformOrigin.Bottom of QQuickItem, and clashes as well with Child for the same enum, because it inherits Base.

       

      To reproduce, I tried to reproduce this in the automated testsuite (of tst_qqmllanguage) and confirmed:

      testtypes.h

       

      class QQuickItemMock : public QObject
      {
          Q_OBJECT
      public:
          enum TransformOrigin {
              TopLeft, Top, TopRight,
              Left, Center, Right,
              BottomLeft, Bottom, BottomRight
          };
          Q_ENUM(TransformOrigin)
      };
      
      class ScopedEnumsWithResolvedNameClashBase : public QQuickItemMock
      {
          Q_OBJECT
          Q_CLASSINFO("RegisterEnumClassesUnscoped", "false")
      
      public:
          enum class ScopedEnum : unsigned int {
              Left,
              Right,
              Bottom,
              OtherScopedEnum
          };
          Q_ENUMS(ScopedEnum)
      };
      
      Q_DECLARE_METATYPE(ScopedEnumsWithResolvedNameClashBase::ScopedEnum)
      
      class ScopedEnumsWithResolvedNameClashInherited : public ScopedEnumsWithResolvedNameClashBase
      {
          Q_OBJECT
          Q_CLASSINFO("RegisterEnumClassesUnscoped", "false")
      
      public:
          Q_PROPERTY( ScopedEnumsWithResolvedNameClashBase::ScopedEnum enumType READ getEnumType CONSTANT)
          ScopedEnumsWithResolvedNameClashBase::ScopedEnum  getEnumType() const { return ScopedEnumsWithResolvedNameClashBase::ScopedEnum::Left; }
      };
      

      tst_qqmllanguage.cpp (abused existing qml files here)

       

      void tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance()
      {
          auto typeId = qmlRegisterUncreatableType<ScopedEnumsWithResolvedNameClashInherited>("ScopedEnumsWithNameClashTest", 1, 0, "ScopedEnum", "Dummy reason");
          auto registryGuard = qScopeGuard([typeId]() {
              qmlUnregisterType(typeId);
          });
      
          QQmlEngine engine;
          QQmlComponent component(&engine, testFileUrl("scopedEnumsWithNameClash.qml"));
      
          QScopedPointer<QObject> obj(component.create());
          QVERIFY(obj != nullptr);
          QVERIFY(obj->property("success").toBool());
      }

       

       

      Following warnings are shown:

       

       

      QWARN : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance() Previously registered enum will be overwritten due to name clash: ScopedEnumsWithResolvedNameClashInherited.TopLeft
      QWARN : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance() Possible conflicting items:
      QWARN : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance() ScopedEnumsWithResolvedNameClashBase.TransformOrigin.TopLeft from scope QQuickItemMock injected by ScopedEnumsWithResolvedNameClashInherited->ScopedEnumsWithResolvedNameClashBase
      QWARN : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance() ScopedEnumsWithResolvedNameClashInherited.TransformOrigin.TopLeft from scope QQuickItemMock injected by ScopedEnumsWithResolvedNameClashInherited
      QWARN : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance() Previously registered enum will be overwritten due to name clash: ScopedEnumsWithResolvedNameClashInherited.Top
      QWARN : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance() Possible conflicting items:
      QWARN : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance() ScopedEnumsWithResolvedNameClashBase.TransformOrigin.Top from scope QQuickItemMock injected by ScopedEnumsWithResolvedNameClashInherited->ScopedEnumsWithResolvedNameClashBase
      QWARN : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance() ScopedEnumsWithResolvedNameClashInherited.TransformOrigin.Top from scope QQuickItemMock injected by ScopedEnumsWithResolvedNameClashInherited
      QWARN : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance() Previously registered enum will be overwritten due to name clash: ScopedEnumsWithResolvedNameClashInherited.TopRight
      QWARN : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance() Possible conflicting items:
      QWARN : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance() ScopedEnumsWithResolvedNameClashBase.TransformOrigin.TopRight from scope QQuickItemMock injected by ScopedEnumsWithResolvedNameClashInherited->ScopedEnumsWithResolvedNameClashBase
      QWARN : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance() ScopedEnumsWithResolvedNameClashInherited.TransformOrigin.TopRight from scope QQuickItemMock injected by ScopedEnumsWithResolvedNameClashInherited QWARN : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance() Previously registered enum will be overwritten due to name clash: ScopedEnumsWithResolvedNameClashInherited.Left
      QWARN : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance() Possible conflicting items:
      QWARN : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance() ScopedEnumsWithResolvedNameClashBase.TransformOrigin.Left from scope QQuickItemMock injected by ScopedEnumsWithResolvedNameClashInherited->ScopedEnumsWithResolvedNameClashBase
      QWARN : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance() ScopedEnumsWithResolvedNameClashBase.ScopedEnum.Left from scope ScopedEnumsWithResolvedNameClashBase injected by ScopedEnumsWithResolvedNameClashInherited->ScopedEnumsWithResolvedNameClashBase
      QWARN : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance() ScopedEnumsWithResolvedNameClashInherited.TransformOrigin.Left from scope QQuickItemMock injected by ScopedEnumsWithResolvedNameClashInherited
      QWARN : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance() ScopedEnumsWithResolvedNameClashInherited.ScopedEnum.Left from scope ScopedEnumsWithResolvedNameClashBase injected by ScopedEnumsWithResolvedNameClashInherited
      QWARN : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance() Previously registered enum will be overwritten due to name clash: ScopedEnumsWithResolvedNameClashInherited.Center
      QWARN : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance() Possible conflicting items:
      QWARN : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance() ScopedEnumsWithResolvedNameClashBase.TransformOrigin.Center from scope QQuickItemMock injected by ScopedEnumsWithResolvedNameClashInherited->ScopedEnumsWithResolvedNameClashBase
      QWARN : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance() ScopedEnumsWithResolvedNameClashInherited.TransformOrigin.Center from scope QQuickItemMock injected by ScopedEnumsWithResolvedNameClashInherited
      QWARN : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance() Previously registered enum will be overwritten due to name clash: ScopedEnumsWithResolvedNameClashInherited.Right
      QWARN : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance() Possible conflicting items:
      QWARN : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance() ScopedEnumsWithResolvedNameClashBase.TransformOrigin.Right from scope QQuickItemMock injected by ScopedEnumsWithResolvedNameClashInherited->ScopedEnumsWithResolvedNameClashBase
      QWARN : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance() ScopedEnumsWithResolvedNameClashBase.ScopedEnum.Right from scope ScopedEnumsWithResolvedNameClashBase injected by ScopedEnumsWithResolvedNameClashInherited->ScopedEnumsWithResolvedNameClashBase
      QWARN : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance() ScopedEnumsWithResolvedNameClashInherited.TransformOrigin.Right from scope QQuickItemMock injected by ScopedEnumsWithResolvedNameClashInherited
      QWARN : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance() ScopedEnumsWithResolvedNameClashInherited.ScopedEnum.Right from scope ScopedEnumsWithResolvedNameClashBase injected by ScopedEnumsWithResolvedNameClashInherited
      QWARN : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance() Previously registered enum will be overwritten due to name clash: ScopedEnumsWithResolvedNameClashInherited.BottomLeft
      QWARN : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance() Possible conflicting items:
      QWARN : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance() ScopedEnumsWithResolvedNameClashBase.TransformOrigin.BottomLeft from scope QQuickItemMock injected by ScopedEnumsWithResolvedNameClashInherited->ScopedEnumsWithResolvedNameClashBase
      QWARN : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance() ScopedEnumsWithResolvedNameClashInherited.TransformOrigin.BottomLeft from scope QQuickItemMock injected by ScopedEnumsWithResolvedNameClashInherited QWARN : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance() Previously registered enum will be overwritten due to name clash: ScopedEnumsWithResolvedNameClashInherited.Bottom
      QWARN : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance() Possible conflicting items:
      QWARN : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance() ScopedEnumsWithResolvedNameClashBase.TransformOrigin.Bottom from scope QQuickItemMock injected by ScopedEnumsWithResolvedNameClashInherited->ScopedEnumsWithResolvedNameClashBase
      QWARN : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance() ScopedEnumsWithResolvedNameClashBase.ScopedEnum.Bottom from scope ScopedEnumsWithResolvedNameClashBase injected by ScopedEnumsWithResolvedNameClashInherited->ScopedEnumsWithResolvedNameClashBase
      QWARN : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance() ScopedEnumsWithResolvedNameClashInherited.TransformOrigin.Bottom from scope QQuickItemMock injected by ScopedEnumsWithResolvedNameClashInherited
      QWARN : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance() ScopedEnumsWithResolvedNameClashInherited.ScopedEnum.Bottom from scope ScopedEnumsWithResolvedNameClashBase injected by ScopedEnumsWithResolvedNameClashInherited
      QWARN : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance() Previously registered enum will be overwritten due to name clash: ScopedEnumsWithResolvedNameClashInherited.BottomRight
      QWARN : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance() Possible conflicting items:
      QWARN : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance() ScopedEnumsWithResolvedNameClashBase.TransformOrigin.BottomRight from scope QQuickItemMock injected by ScopedEnumsWithResolvedNameClashInherited->ScopedEnumsWithResolvedNameClashBase
      QWARN : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance() ScopedEnumsWithResolvedNameClashInherited.TransformOrigin.BottomRight from scope QQuickItemMock injected by ScopedEnumsWithResolvedNameClashInherited PASS : tst_qqmllanguage::scopedEnumsWithResolvedNameClashInheritance()
      

      If it just would be a design error, please feel free to close this ticket.

      Thanks.

       

       

      Attachments

        For Gerrit Dashboard: QTBUG-71184
        # Subject Branch Project Status CR V

        Activity

          People

            shausman Simon Hausmann
            bartel Bartel Eerdekens
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes