path: root/src/corelib/kernel/qmetatype.cpp
diff options
authorStephen Kelly <>2013-09-08 08:49:29 +0200
committerThe Qt Project <>2013-09-11 12:24:42 +0200
commit546d52e605b6a74d9a5be26fb374b831a46f2550 (patch)
treec48f2e75179c44f5bee37ee2c5d8b8afcc4d072a /src/corelib/kernel/qmetatype.cpp
parent3256856bbea22da03109b84ef407e8dbc69930e7 (diff)
Add a convenient way to get a type-erased smart pointer from a QVariant.
Any known smart pointer in a QVariant can be handled in this way. The metatype system can be informed of new smart pointer types using an existing macro which is now documented. This is very similar to the existing infrastructure for containers. Change-Id: Iac4f9fabbc5a0626c04e1185d51d720b8b54603d Reviewed-by: Olivier Goffart <>
Diffstat (limited to 'src/corelib/kernel/qmetatype.cpp')
1 files changed, 16 insertions, 0 deletions
diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp
index 2ab6681bb9..70c2e236dd 100644
--- a/src/corelib/kernel/qmetatype.cpp
+++ b/src/corelib/kernel/qmetatype.cpp
@@ -175,6 +175,22 @@ struct DefinedTypesFilter {
+ \relates QMetaType
+ This macro makes the smart pointer \a 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.
+ Note that the QWeakPointer, QSharedPointer and QPointer already have built-in
+ support, and it is not necessary to use this macro with them.
+ This example shows a typical use of Q_DECLARE_SMART_POINTER_METATYPE():
+ \snippet code/src_corelib_kernel_qmetatype.cpp 13
\enum QMetaType::Type
These are the built-in types supported by QMetaType: