diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2019-05-10 20:59:52 +0200 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2019-05-16 13:59:52 +0000 |
commit | b7a7d61efc7319ed8ce111ba20d14403b1161ce8 (patch) | |
tree | 3550dec5698b48b681e5de3777892490921bc1ac /src/corelib | |
parent | 5497183c71de352324cab05f3c0a768be75a236a (diff) |
Deprecate QWeakPointer::data()
It's a dangerous API to have. Upgrade to a shared pointer
if accessing the raw pointer is required.
[ChangeLog][QtCore][QWeakPointer] The data() function has
been deprecated.
Change-Id: Ie5d34f4fb500b3cfa14d2c0b1b08484df072129c
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/kernel/qpointer.h | 2 | ||||
-rw-r--r-- | src/corelib/tools/qsharedpointer.cpp | 7 | ||||
-rw-r--r-- | src/corelib/tools/qsharedpointer_impl.h | 4 |
3 files changed, 6 insertions, 7 deletions
diff --git a/src/corelib/kernel/qpointer.h b/src/corelib/kernel/qpointer.h index 016658ee60..3e92289792 100644 --- a/src/corelib/kernel/qpointer.h +++ b/src/corelib/kernel/qpointer.h @@ -83,7 +83,7 @@ public: { wp.assign(static_cast<QObjectType*>(p)); return *this; } inline T* data() const - { return static_cast<T*>( wp.data()); } + { return static_cast<T*>(wp.d == nullptr || wp.d->strongref.load() == 0 ? nullptr : wp.value); } inline T* operator->() const { return data(); } inline T& operator*() const diff --git a/src/corelib/tools/qsharedpointer.cpp b/src/corelib/tools/qsharedpointer.cpp index ad95176ae1..e4de5a2ba9 100644 --- a/src/corelib/tools/qsharedpointer.cpp +++ b/src/corelib/tools/qsharedpointer.cpp @@ -343,12 +343,6 @@ if you obtain a non-null object, you may use the pointer. See QWeakPointer::toStrongRef() for an example. - QWeakPointer also provides the QWeakPointer::data() method that returns - the tracked pointer without ensuring that it remains valid. This function - is provided if you can guarantee by external means that the object will - not get deleted (or if you only need the pointer value) and the cost of - creating a QSharedPointer using toStrongRef() is too high. - \omit \section1 QWeakPointer internals @@ -853,6 +847,7 @@ /*! \fn template <class T> T *QWeakPointer<T>::data() const \since 4.6 + \obsolete Use toStrongRef() instead, and data() on the returned QSharedPointer. Returns the value of the pointer being tracked by this QWeakPointer, \b without ensuring that it cannot get deleted. To have that guarantee, diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h index 80543f1983..d16a7c6659 100644 --- a/src/corelib/tools/qsharedpointer_impl.h +++ b/src/corelib/tools/qsharedpointer_impl.h @@ -565,7 +565,11 @@ public: bool isNull() const noexcept { return d == nullptr || d->strongref.load() == 0 || value == nullptr; } operator RestrictedBool() const noexcept { return isNull() ? nullptr : &QWeakPointer::value; } bool operator !() const noexcept { return isNull(); } + +#if QT_DEPRECATED_SINCE(5, 14) + QT_DEPRECATED_X("Use toStrongRef() instead, and data() on the returned QSharedPointer") T *data() const noexcept { return d == nullptr || d->strongref.load() == 0 ? nullptr : value; } +#endif inline QWeakPointer() noexcept : d(nullptr), value(nullptr) { } inline ~QWeakPointer() { if (d && !d->weakref.deref()) delete d; } |