From e5a6e9bb80fb2427228f70488b8839b4aa0b4261 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Wed, 7 Mar 2018 08:43:51 +0100 Subject: Doc: improve QScopedPointer::reset() documentation - Fix grammar - Mention take() Change-Id: I3bde229755549230ad3d0962da6eeb164a060fb1 Reviewed-by: Andy Shaw --- src/corelib/tools/qscopedpointer.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/corelib') diff --git a/src/corelib/tools/qscopedpointer.cpp b/src/corelib/tools/qscopedpointer.cpp index 6c24e19bfa..769a18f9e0 100644 --- a/src/corelib/tools/qscopedpointer.cpp +++ b/src/corelib/tools/qscopedpointer.cpp @@ -250,9 +250,12 @@ QT_BEGIN_NAMESPACE /*! \fn template void QScopedPointer::reset(T *other = 0) - Deletes the existing object it is pointing to if any, and sets its pointer to + Deletes the existing object it is pointing to (if any), and sets its pointer to \a other. QScopedPointer now owns \a other and will delete it in its destructor. + + To clear the pointer held without deleting the object it points to (and hence take ownership + of the object), use \l take() instead. */ /*! -- cgit v1.2.3 From fee8944cbe2a976e1b4a71c5df048e84a0bc6db0 Mon Sep 17 00:00:00 2001 From: Nils Jeisecke Date: Fri, 2 Mar 2018 16:57:11 +0100 Subject: Allow use of template class instances inheriting from a Q_GADGET in Qml The Q_GADGET macro cannot be used in templates. It can however be useful to derive a template class from a Q_GADGET enabled base class to benefit from type safety features in C++ (e.g. the class could represent an id or handle for some C++ type). For proper wrapping of a QVariant with a gadget value in a QJSValue, the QMetaType::IsGadget flag must be set for the registered template instance type - which does not happen prior to the fix because IsGadgetHelper requires qt_check_for_QGADGET_macro to be defined in the registered class but not in an ancestor class - in other words: The class must declare Q_GADGET. To overcome this, IsGadgetHelper/IsPointerToGadgetHelper can now differentiate between a Q_GADGET flagged class (allowing automatic registration) and a derived class, e.g. a template class (forcing Q_DECLARE_METATYPE to be used explicitly). [ChangeLog][QtCore][QMetaObject] It is now possible to use template class instances inheriting from a Q_GADGET in Qml Task-number: QTBUG-66744 Change-Id: I7632ad45cff79fa422b3f852ca0b963f35fab155 Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/corelib/kernel/qmetatype.h | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h index 455d0350e0..4674efe568 100644 --- a/src/corelib/kernel/qmetatype.h +++ b/src/corelib/kernel/qmetatype.h @@ -1381,7 +1381,7 @@ namespace QtPrivate }; template - struct IsGadgetHelper { enum { Value = false }; }; + struct IsGadgetHelper { enum { IsRealGadget = false, IsGadgetOrDerivedFrom = false }; }; template struct IsGadgetHelper @@ -1389,11 +1389,14 @@ namespace QtPrivate template static char checkType(void (X::*)()); static void *checkType(void (T::*)()); - enum { Value = sizeof(checkType(&T::qt_check_for_QGADGET_macro)) == sizeof(void *) }; + enum { + IsRealGadget = sizeof(checkType(&T::qt_check_for_QGADGET_macro)) == sizeof(void *), + IsGadgetOrDerivedFrom = true + }; }; template - struct IsPointerToGadgetHelper { enum { Value = false }; }; + struct IsPointerToGadgetHelper { enum { IsRealGadget = false, IsGadgetOrDerivedFrom = false }; }; template struct IsPointerToGadgetHelper @@ -1402,7 +1405,10 @@ namespace QtPrivate template static char checkType(void (X::*)()); static void *checkType(void (T::*)()); - enum { Value = sizeof(checkType(&T::qt_check_for_QGADGET_macro)) == sizeof(void *) }; + enum { + IsRealGadget = sizeof(checkType(&T::qt_check_for_QGADGET_macro)) == sizeof(void *), + IsGadgetOrDerivedFrom = true + }; }; @@ -1435,12 +1441,12 @@ namespace QtPrivate static inline const QMetaObject *value() { return &T::staticMetaObject; } }; template - struct MetaObjectForType::Value>::type> + struct MetaObjectForType::IsGadgetOrDerivedFrom>::type> { static inline const QMetaObject *value() { return &T::staticMetaObject; } }; template - struct MetaObjectForType::Value>::Type> + struct MetaObjectForType::IsGadgetOrDerivedFrom>::type> { static inline const QMetaObject *value() { return &IsPointerToGadgetHelper::BaseType::staticMetaObject; } }; @@ -1599,8 +1605,8 @@ namespace QtPrivate template ::Value ? QMetaType::PointerToQObject : - QtPrivate::IsGadgetHelper::Value ? QMetaType::IsGadget : - QtPrivate::IsPointerToGadgetHelper::Value ? QMetaType::PointerToGadget : + QtPrivate::IsGadgetHelper::IsRealGadget ? QMetaType::IsGadget : + QtPrivate::IsPointerToGadgetHelper::IsRealGadget ? QMetaType::PointerToGadget : QtPrivate::IsQEnumHelper::Value ? QMetaType::IsEnumeration : 0> struct QMetaTypeIdQObject { @@ -1653,8 +1659,8 @@ namespace QtPrivate { | (IsWeakPointerToTypeDerivedFromQObject::Value ? QMetaType::WeakPointerToQObject : 0) | (IsTrackingPointerToTypeDerivedFromQObject::Value ? QMetaType::TrackingPointerToQObject : 0) | (std::is_enum::value ? QMetaType::IsEnumeration : 0) - | (IsGadgetHelper::Value ? QMetaType::IsGadget : 0) - | (IsPointerToGadgetHelper::Value ? QMetaType::PointerToGadget : 0) + | (IsGadgetHelper::IsGadgetOrDerivedFrom ? QMetaType::IsGadget : 0) + | (IsPointerToGadgetHelper::IsGadgetOrDerivedFrom ? QMetaType::PointerToGadget : 0) }; }; -- cgit v1.2.3