summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qsharedpointer_impl.h
diff options
context:
space:
mode:
authorStephen Kelly <stephen.kelly@kdab.com>2012-05-25 10:31:03 +0200
committerQt by Nokia <qt-info@nokia.com>2012-06-07 19:08:51 +0200
commitee7fa67eb0060b9c794bae4c7b06110c3b9626e0 (patch)
tree13401c7dcdb54f1e7ffbdd9c5a369c5c371dacdd /src/corelib/tools/qsharedpointer_impl.h
parent77a03ebd8da28c3811fe505b2a84e2d42743005f (diff)
Deprecate the use of QWeakPointer to track QObjects.
The main problem with using QWeakPointer to track QObjects is that it has API to convert to QSharedPointer, which is undefined behavior. There is no need to overload the meaning of QWeakPointer with QObject tracking. QPointer is more suitable and should be used instead. Because QPointer is implemented in terms of QWeakPointer, we need to add some overloads which are not deprecated. Change-Id: If0333e4800c9fd277629cc69185c9ca3e4e7e81d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qsharedpointer_impl.h')
-rw-r--r--src/corelib/tools/qsharedpointer_impl.h20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h
index 4a9327fe81..d1d660dfc7 100644
--- a/src/corelib/tools/qsharedpointer_impl.h
+++ b/src/corelib/tools/qsharedpointer_impl.h
@@ -585,13 +585,18 @@ public:
#ifndef QT_NO_QOBJECT
// special constructor that is enabled only if X derives from QObject
+#if QT_DEPRECATED_SINCE(5, 0)
template <class X>
- inline QWeakPointer(X *ptr) : d(ptr ? d->getAndRef(ptr) : 0), value(ptr)
+ QT_DEPRECATED inline QWeakPointer(X *ptr) : d(ptr ? d->getAndRef(ptr) : 0), value(ptr)
{ }
#endif
+#endif
+
+#if QT_DEPRECATED_SINCE(5, 0)
template <class X>
- inline QWeakPointer &operator=(X *ptr)
+ QT_DEPRECATED inline QWeakPointer &operator=(X *ptr)
{ return *this = QWeakPointer(ptr); }
+#endif
inline QWeakPointer(const QWeakPointer<T> &o) : d(o.d), value(o.value)
{ if (d) d->weakref.ref(); }
@@ -664,6 +669,17 @@ private:
public:
#else
template <class X> friend class QSharedPointer;
+ friend class QPointerBase;
+#endif
+
+ template <class X>
+ inline QWeakPointer &assign(X *ptr)
+ { return *this = QWeakPointer<X>(ptr, true); }
+
+#ifndef QT_NO_QOBJECT
+ template <class X>
+ inline QWeakPointer(X *ptr, bool) : d(ptr ? d->getAndRef(ptr) : 0), value(ptr)
+ { }
#endif
inline void internalSet(Data *o, T *actual)