[Interest] Q_DECLARE_SMART_POINTER_METATYPE type restriction

Thiago Macieira thiago.macieira at intel.com
Tue Jan 28 23:55:42 CET 2020


On Tuesday, 28 January 2020 12:59:04 PST joel at embedded.pro wrote:
> For this, I've been looking at Q_DECLARE_SMART_POINTER_METATYPE. The 
documentation has the following to say about this macro:
> >> This macro makes the smart pointer SmartPointer known to QMetaType as a
> >> smart pointer. This makes it possible to put an instance of
> >> SmartPointer<T> into a QVariant, if T is a type which inherits QObject.
> I'd be interested to know why T would be restricted to a type which inherits
> QObject.
> 
> Can anybody enlighten me?

The point of the feature is to teach QVariant how to recognise QObject 
pointers and provide the rest of the QObject-like API.

If your type does not derive from QObject, don't use this macro. Register your 
smart pointer instantiation like any other class.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel System Software Products





More information about the Interest mailing list