diff options
author | Stephen Kelly <stephen.kelly@kdab.com> | 2012-06-09 22:57:35 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-06-20 15:45:07 +0200 |
commit | 668efc29fd85bbae2395a4eca8d0ad71ad6ee3d1 (patch) | |
tree | ffccf50b396428156cafb3c6a51ddb87d2359f28 /src/corelib/kernel/qpointer.h | |
parent | 534bcc96676ac02fc327f9e43d3785c7424b0750 (diff) |
Add some internal API for extracting a QSharedPointer<T> from QVariant.
The T must be derived from QObject, or it will fail to compile.
This will allow scripting or other 'wrapping' and runtime environments like
QtDeclarative to handle QSharedPointers to types derived from QObject
properly. A QSharedPointer<T> can be inserted into a QVariant, and
where T derives from QObject, a QSharedPointer<QObject> can be
extracted from the QVariant, and its properties are then accessible.
Change-Id: I68d6d89aceceb019267bd7301baa2047f9c09b90
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/kernel/qpointer.h')
-rw-r--r-- | src/corelib/kernel/qpointer.h | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/corelib/kernel/qpointer.h b/src/corelib/kernel/qpointer.h index 88d8225621..ef1d4dc1d5 100644 --- a/src/corelib/kernel/qpointer.h +++ b/src/corelib/kernel/qpointer.h @@ -50,6 +50,7 @@ QT_BEGIN_HEADER QT_BEGIN_NAMESPACE +class QVariant; class QPointerBase { @@ -184,6 +185,13 @@ inline bool operator!= (int i, const QPointer<T> &p) { Q_ASSERT(i == 0); return !i && !p.isNull(); } #endif +template<typename T> +QPointer<T> +qPointerFromVariant(const QVariant &variant) +{ + return QPointer<T>(qobject_cast<T*>(QtSharedPointer::weakPointerFromVariant_internal(variant).data())); +} + QT_END_NAMESPACE QT_END_HEADER |