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

Can not use enum (class) as slot argument with underlying type (unsigned) long, e.g. std::uint64_t

    XMLWordPrintable

Details

    • All
    • 0c010cd9c (dev)

    Description

      I've been using Qt 6 commit 174154bcac2780cb704011662f2e9c1233fec933 (from Fri Aug 21 13:01:43). Maybe the problem stated in the summary has already been fixed.

      The compile error looks like this:

      /usr/include/qt6/QtCore/qdatastream.h:421:12: error: use of overloaded operator '<<' is ambiguous (with operand types 'QDataStream' and 'typename std::underlying_type<EnumClassUsingUnsignedLong>::type' (aka 'long'))
      { return s << static_cast<typename std::underlying_type<T>::type>(t); }
       ~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      /usr/include/qt6/QtCore/qmetatype.h:2435:10: note: in instantiation of function template specialization 'operator<<<QtGui::EnumClassUsingUnsignedLong>' requested here
       \{ ds << *reinterpret_cast<const T *>(a); }
       ^
      /usr/include/qt6/QtCore/qmetatype.h:2534:56: note: in instantiation of member function 'QtPrivate::QDataStreamOperatorForType<QtGui::EnumClassUsingUnsignedLong, true>::dataStreamOut' requested here
       /*.dataStreamOut=*/ QDataStreamOperatorForType<T>::dataStreamOut,
       ^
      /usr/include/qt6/QtCore/qmetatype.h:2645:39: note: in instantiation of static data member 'QtPrivate::QMetaTypeForType<QtGui::EnumClassUsingUnsignedLong>::metaType' requested here
       return &QMetaTypeForType<Ty>::metaType;
      

      Code snipped to reproduce the compile error:

      enum EnumClassUsingUnsignedLong : long {
          Foo,
          Bar,
      };
      
      class Test : public QObject {
          Q_OBJECT
      
      public Q_SLOTS:
          void foo(EnumClassUsingUnsignedLong bar);
      };
      

      It also doesn't work with unsigned long and when using enum class.

      Likely it is just missing an overload for long and unsigned long.
       

       

       

      Attachments

        Issue Links

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

          Activity

            People

              thiago Thiago Macieira
              martchus martchus
              Votes:
              1 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes