add QScopedPointerDeleteLater, a custom deleter for QObjects
This is a custom deleter for QObjects that are participating in an event loop (e.g. waiting for signals to complete a task), which need to be deleted using deleteLater() rather than just delete. Change-Id: I3084ea28a6829a299c7400006c617fc23cf15160 Reviewed-by: J-P Nurmi <jpnurmi@digia.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
b3a56454c3
commit
ade0d8361c
@ -95,6 +95,9 @@ QT_BEGIN_NAMESPACE
|
||||
this handler for pointers that were allocated with \c{new []}.
|
||||
\li QScopedPointerPodDeleter - deletes the pointer using \c{free()}. Use this
|
||||
handler for pointers that were allocated with \c{malloc()}.
|
||||
\li QScopedPointerDeleteLater - deletes a pointer by calling \c{deleteLater()}
|
||||
on it. Use this handler for pointers to QObject's that are actively
|
||||
participating in a QEventLoop.
|
||||
\endlist
|
||||
|
||||
You can pass your own classes as handlers, provided that they have a public
|
||||
|
@ -83,6 +83,17 @@ struct QScopedPointerPodDeleter
|
||||
static inline void cleanup(void *pointer) { if (pointer) free(pointer); }
|
||||
};
|
||||
|
||||
#ifndef QT_NO_QOBJECT
|
||||
template <typename T>
|
||||
struct QScopedPointerObjectDeleteLater
|
||||
{
|
||||
static inline void cleanup(T *pointer) { if (pointer) pointer->deleteLater(); }
|
||||
};
|
||||
|
||||
class QObject;
|
||||
typedef QScopedPointerObjectDeleteLater<QObject> QScopedPointerDeleteLater;
|
||||
#endif
|
||||
|
||||
template <typename T, typename Cleanup = QScopedPointerDeleter<T> >
|
||||
class QScopedPointer
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user