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

Signals carrying smart pointers to const QObject fail to compile

    XMLWordPrintable

Details

    • c613dd4765 (qt/qtbase/dev) c613dd4765 (qt/tqtc-qtbase/dev) 81b19819b3 (qt/qtbase/6.3) 81b19819b3 (qt/tqtc-qtbase/6.3) 81b19819b3 (qt/qtbase/6.3.1)

    Description

      A QObject subclass declaring a signal that carries a smart pointer to a const QObject will fail to compile:

      ../src/qt5/qtbase/build/include/QtCore/../../../src/corelib/kernel/qmetatype.h: In instantiation of ‘QObject* QtPrivate::QSmartPointerConvertFunctor<SmartPointer>::operator()(const SmartPointer&) const [with SmartPointer = QSharedPointer<const Test>]’:
      ../src/qt5/qtbase/build/include/QtCore/../../../src/corelib/kernel/qmetatype.h:613:26:   required from ‘static bool QMetaType::registerConverter(UnaryFunction) [with From = QSharedPointer<const Test>; To = QObject*; UnaryFunction = QtPrivate::QSmartPointerConvertFunctor<QSharedPointer<const Test> >]’
      ../src/qt5/qtbase/build/include/QtCore/../../../src/corelib/kernel/qmetatype.h:1630:1:   required from ‘static bool QtPrivate::MetaTypeSmartPointerHelper<QSharedPointer<T>, typename std::enable_if<QtPrivate::IsPointerToTypeDerivedFromQObject<T*>::Value>::type>::registerConverter() [with T = const Test]’
      ../src/qt5/qtbase/build/include/QtCore/../../../src/corelib/kernel/qmetatype.h:1245:64:   required from ‘int qRegisterNormalizedMetaTypeImplementation(const QByteArray&) [with T = QSharedPointer<const Test>]’
      ../src/qt5/qtbase/build/include/QtCore/../../../src/corelib/kernel/qmetatype.h:1269:56:   required from ‘int qRegisterNormalizedMetaType(const QByteArray&) [with T = QSharedPointer<const Test>]’
      ../src/qt5/qtbase/build/include/QtCore/../../../src/corelib/kernel/qmetatype.h:1630:1:   required from ‘static int QtPrivate::SharedPointerMetaTypeIdHelper<QSharedPointer<T>, true>::qt_metatype_id() [with T = const Test]’
      ../src/qt5/qtbase/build/include/QtCore/../../../src/corelib/kernel/qmetatype.h:1145:89:   required from ‘static constexpr int QMetaTypeId2<T>::qt_metatype_id() [with T = QSharedPointer<const Test>]’
      ../src/qt5/qtbase/build/include/QtCore/../../../src/corelib/kernel/qmetatype.h:2343:58:   required from ‘static constexpr void (* QtPrivate::QMetaTypeForType<S>::getLegacyRegister())() [with S = QSharedPointer<const Test>; QtPrivate::QMetaTypeInterface::LegacyRegisterOp = void (*)()]’
      ../src/qt5/qtbase/build/include/QtCore/../../../src/corelib/kernel/qmetatype.h:2379:70:   required from ‘constexpr const QtPrivate::QMetaTypeInterface QtPrivate::QMetaTypeInterfaceWrapper<QSharedPointer<const Test> >::metaType’
      ../src/qt5/qtbase/build/include/QtCore/../../../src/corelib/kernel/qmetatype.h:2493:16:   required from ‘constexpr const QtPrivate::QMetaTypeInterface* QtPrivate::qTryMetaTypeInterfaceForType() [with Unique = qt_meta_stringdata_A_t; TypeCompletePair = TypeAndForceComplete<const QSharedPointer<const Test>&, std::integral_constant<bool, false> >]’
      ../src/qt5/qtbase/build/include/QtCore/../../../src/corelib/kernel/qmetatype.h:2537:55:   required from ‘constexpr const QtPrivate::QMetaTypeInterface* const qt_incomplete_metaTypeArray [5]<qt_meta_stringdata_A_t, QtPrivate::TypeAndForceComplete<A, std::integral_constant<bool, true> >, QtPrivate::TypeAndForceComplete<void, std::integral_constant<bool, false> >, QtPrivate::TypeAndForceComplete<const QSharedPointer<const C>&, std::integral_constant<bool, false> >, QtPrivate::TypeAndForceComplete<void, std::integral_constant<bool, false> >, QtPrivate::TypeAndForceComplete<const QSharedPointer<const Test>&, std::integral_constant<bool, false> > >’
      moc_a.cpp:180:1:   required from here
      ../src/qt5/qtbase/build/include/QtCore/../../../src/corelib/kernel/qmetatype.h:1208:32: error: invalid conversion from ‘const QObject*’ to ‘QObject*’ [-fpermissive]
       1208 |             return p.operator->();
            |                    ~~~~~~~~~~~~^~
            |                                |
            |                                const QObject*
      

      Moc-generated code will trigger QMetaType type registration, which will try to register a converter from the shared pointer to QObject *. That however converter does not compile because it would drop constness from the pointer.

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            peppe Giuseppe D'Angelo
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes