From 668efc29fd85bbae2395a4eca8d0ad71ad6ee3d1 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sat, 9 Jun 2012 22:57:35 +0200 Subject: Add some internal API for extracting a QSharedPointer 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 can be inserted into a QVariant, and where T derives from QObject, a QSharedPointer can be extracted from the QVariant, and its properties are then accessible. Change-Id: I68d6d89aceceb019267bd7301baa2047f9c09b90 Reviewed-by: Thiago Macieira --- src/corelib/tools/qsharedpointer.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/corelib/tools/qsharedpointer.cpp') diff --git a/src/corelib/tools/qsharedpointer.cpp b/src/corelib/tools/qsharedpointer.cpp index 8ca153f433..73a1e6c607 100644 --- a/src/corelib/tools/qsharedpointer.cpp +++ b/src/corelib/tools/qsharedpointer.cpp @@ -1214,6 +1214,26 @@ QtSharedPointer::ExternalRefCountData *QtSharedPointer::ExternalRefCountData::ge return x; } +/** + \internal + Returns a QSharedPointer if the variant contains + a QSharedPointer where T inherits QObject. Otherwise the behaviour is undefined. +*/ +QSharedPointer QtSharedPointer::sharedPointerFromVariant_internal(const QVariant &variant) +{ + return *reinterpret_cast*>(variant.constData()); +} + +/** + \internal + Returns a QWeakPointer if the variant contains + a QWeakPointer where T inherits QObject. Otherwise the behaviour is undefined. +*/ +QWeakPointer QtSharedPointer::weakPointerFromVariant_internal(const QVariant &variant) +{ + return *reinterpret_cast*>(variant.constData()); +} + QT_END_NAMESPACE #endif -- cgit v1.2.3