Skip to content

Remove unneeded Q_DECLARE_METATYPE calls for pointers to QObject subclasses

Compare API dox of Q_DECLARE_METATYPE:

Some types are registered automatically and do not need this macro:

  • Pointers to classes derived from QObject
  • QPointer, QSharedPointer, QWeakPointer, where T is a class that derives from QObject

This is a ABI-compatible change, as this just replaces explicitly defined template code (by the Q_DECLARE_METATYPE macro use) with the generic predefined one picking up pointers to QObject subclasses.

So instead of the custom explicitly template overload

    template <>
    struct QMetaTypeId< TYPE >
    { /**/ static int qt_metatype_id() {/**/} };

the predefined template overload one is picked up via

    template <typename T>
    struct QMetaTypeId : public QMetaTypeIdQObject<T>
    { /**/ };
    template <typename T, int =
        QtPrivate::IsPointerToTypeDerivedFromQObject<T>::Value ?
            QMetaType::PointerToQObject :
        /**/ 0>
    struct QMetaTypeIdQObject
    { /**/ };
    template <typename T>
    struct QMetaTypeIdQObject<T*, QMetaType::PointerToQObject>
    { /**/ static int qt_metatype_id() {/**/} };

And thus the constexpr code using QMetaTypeId::qt_metatype_id(), for which all this is done, evaluates as before.

GIT_SILENT

Edited by Friedrich W. H. Kossebau

Merge request reports

Loading