diff options
author | Bradley T. Hughes <bradley.hughes@nokia.com> | 2011-11-22 14:45:35 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-12-10 16:11:48 +0100 |
commit | 6f0f9f69288925ef423c542ef5eb7302a5431867 (patch) | |
tree | a0ded9966183fb45b7868d25350affa2259f29a1 /src/corelib/kernel/qpointer.cpp | |
parent | a6ae75f92a8628c727a9c5a9961fa91c583c008e (diff) |
Remove QMetaObject guards and deprecate QPointer.
QWeakPointer is superior and preferred.
Remove QMetaObject::addGuard(), QMetaObject::changeGuard(),
QMetaObject::removeGuard(), and QObjectPrivate::clearGuards().
Implement QPointer using QWeakPointer<T> instead. This changes the
behavior of QPointer in 2 ways:
- During destruction of a QWidget. Previously, the destructor of QWidget
would reset all QPointers so that they would return zero when destroying
children. Update tst_QPointer to account for this change.
- When constructing a QSharedPointer to take ownership of an object
after a QPointer is already tracking the object. Previously, the shared
pointer construction would not be affected by the QPointer, but now
that QPointer is implemented using QWeakPoiner, constructing the
QSharedPointer will cause an abort(). Fix tst_QSharedPointer by
removing the use of QPointer in the objectCast() test.
These behavior changes are documented in the QPointer class
documentation and in the changes file.
Change-Id: I92d0276219c076ece7bcb60f6e1b9120ce4f5747
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'src/corelib/kernel/qpointer.cpp')
-rw-r--r-- | src/corelib/kernel/qpointer.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/corelib/kernel/qpointer.cpp b/src/corelib/kernel/qpointer.cpp index c7fcf4f1e8..51c8b2ad74 100644 --- a/src/corelib/kernel/qpointer.cpp +++ b/src/corelib/kernel/qpointer.cpp @@ -44,7 +44,7 @@ \brief The QPointer class is a template class that provides guarded pointers to QObject. \ingroup objectmodel - + \obsolete Use QWeakPointer instead. A guarded pointer, QPointer<T>, behaves like a normal C++ pointer \c{T *}, except that it is automatically set to 0 when the @@ -57,6 +57,24 @@ destroyed while you still hold a reference to it. You can safely test the pointer for validity. + Note that Qt 5 introduces two slight changes in behavior when using QPointer. + + \list + + \i When using QPointer on a QWidget (or a subclass of QWidget), previously + the QPointer would be cleared by the QWidget destructor. Now, the QPointer + is cleared by the QObject destructor (since this is when QWeakPointers are + cleared). Any QPointers tracking a widget will \b NOT be cleared before the + QWidget destructor destroys the children for the widget being tracked. + + \i When constructing a QSharedPointer to take ownership of an object after a + QPointer is already tracking the object. Previously, the shared pointer + construction would not be affected by the QPointer, but now that QPointer + is implemented using QWeakPoiner, constructing the QSharedPointer will + cause an \c abort(). + + \endlist + Qt also provides QSharedPointer, an implementation of a reference-counted shared pointer object, which can be used to maintain a collection of references to an individual pointer. |