summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qmetatype.h
diff options
context:
space:
mode:
authorStephen Kelly <stephen.kelly@kdab.com>2013-09-05 18:03:44 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-06 16:18:32 +0200
commit2ff15ff065ef5f189ba8727ec6424c0e79285864 (patch)
treee28b3bc6eeb2c708cffad05da720d5145fcd274b /src/corelib/kernel/qmetatype.h
parent87ff0af425656d12c4766a57db60674d63ffa584 (diff)
Fix the automatic declaration of smart pointer types.
Before this patch, qRegisterMetaType<QSharedPointer<double> >("QSharedPointer<double>") without a metatype declaration fails to compile, whereas it works with Qt 5.1 (ie, before commit e9a69c3ba928bd88974563b386b000ad6583f969) Change-Id: I9408f711c9df810ff29b879b7696dab81c1160f1 Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
Diffstat (limited to 'src/corelib/kernel/qmetatype.h')
-rw-r--r--src/corelib/kernel/qmetatype.h40
1 files changed, 34 insertions, 6 deletions
diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h
index 5ce3f26b53..80c1f21c0d 100644
--- a/src/corelib/kernel/qmetatype.h
+++ b/src/corelib/kernel/qmetatype.h
@@ -1789,16 +1789,32 @@ struct QMetaTypeId< DOUBLE_ARG_TEMPLATE<T, U> > \
} \
};
+namespace QtPrivate {
+
+template<typename T, bool /* isSharedPointerToQObjectDerived */ = false>
+struct SharedPointerMetaTypeIdHelper
+{
+ enum {
+ Defined = 0
+ };
+ static int qt_metatype_id()
+ {
+ return -1;
+ }
+};
+
+}
+
#define Q_DECLARE_SMART_POINTER_METATYPE(SMART_POINTER) \
-template <typename T> \
-struct QMetaTypeId< SMART_POINTER<T> > \
+QT_BEGIN_NAMESPACE \
+namespace QtPrivate { \
+template<typename T> \
+struct SharedPointerMetaTypeIdHelper<SMART_POINTER<T>, true> \
{ \
enum { \
- Defined = QtPrivate::IsPointerToTypeDerivedFromQObject<T*>::Value \
+ Defined = 1 \
}; \
- static \
- typename QtPrivate::QEnableIf<QtPrivate::IsPointerToTypeDerivedFromQObject<T*>::Value, int>::Type \
- qt_metatype_id() \
+ static int qt_metatype_id() \
{ \
static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0); \
if (const int id = metatype_id.loadAcquire()) \
@@ -1814,7 +1830,15 @@ struct QMetaTypeId< SMART_POINTER<T> > \
metatype_id.storeRelease(newId); \
return newId; \
} \
+}; \
+} \
+template <typename T> \
+struct QMetaTypeId< SMART_POINTER<T> > \
+ : QtPrivate::SharedPointerMetaTypeIdHelper< SMART_POINTER<T>, \
+ QtPrivate::IsPointerToTypeDerivedFromQObject<T*>::Value> \
+{ \
};\
+QT_END_NAMESPACE \
#define QT_FOR_EACH_AUTOMATIC_TEMPLATE_SMART_POINTER(F) \
F(QSharedPointer) \
@@ -1846,8 +1870,12 @@ Q_DECLARE_METATYPE_TEMPLATE_2ARG(std::map)
#define Q_DECLARE_METATYPE_TEMPLATE_SMART_POINTER_ITER(TEMPLATENAME) \
Q_DECLARE_SMART_POINTER_METATYPE(TEMPLATENAME)
+QT_END_NAMESPACE
+
QT_FOR_EACH_AUTOMATIC_TEMPLATE_SMART_POINTER(Q_DECLARE_METATYPE_TEMPLATE_SMART_POINTER_ITER)
+QT_BEGIN_NAMESPACE
+
#undef Q_DECLARE_METATYPE_TEMPLATE_SMART_POINTER_ITER
inline QMetaType::QMetaType(const ExtensionFlag extensionFlags, const QMetaTypeInterface *info,