[Interest] Q_DECLARE_SMART_POINTER_METATYPE type restriction

joel at embedded.pro joel at embedded.pro
Tue Jan 28 21:59:04 CET 2020


Hi,

 

I was investigating the idea of storing an std::shared_ptr<T> in a QVariant. This would allow me to put a shared pointer to my custom data int a QComboBox's data field.

I'm aware of the existence of QSharedPointer. The data I am working with is only available wrapped into an std::shared_ptr (data provided by a 3rd party component). This leaves me with the choice of either storing raw pointers or registering my own type for the use with QVariant.

 

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?

 

I’ve also posted this on the forum. Samuel recommended me to post the question on this list instead tho: https://forum.qt.io/topic/111114/q_declare_smart_pointer_metatype-type-restriction

 

 

~ Joel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20200128/06f91bde/attachment.html>


More information about the Interest mailing list