Cleanup the fallout of QWeakPointer::data() deprecation
There are still users of QWeakPointer::data(), which under certain compilers will make headersclean fail. So this patch: * ports data() to a private internalData() function and calls it from all the usage points; * adds cleanup notes for Qt 6, once some of the deprecated machinery around storing unmanaged QObjects in QWeakPointers can get removed. Change-Id: Id3bcbd23374c18a2026861c08a4dcba1670673c1 Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Mike Krus <mike.krus@kdab.com>
This commit is contained in:
parent
edb53d761e
commit
28ce318fcb
@ -83,7 +83,7 @@ public:
|
||||
{ wp.assign(static_cast<QObjectType*>(p)); return *this; }
|
||||
|
||||
inline T* data() const
|
||||
{ return static_cast<T*>(wp.d == nullptr || wp.d->strongref.load() == 0 ? nullptr : wp.value); }
|
||||
{ return static_cast<T*>(wp.internalData()); }
|
||||
inline T* operator->() const
|
||||
{ return data(); }
|
||||
inline T& operator*() const
|
||||
@ -143,7 +143,7 @@ template<typename T>
|
||||
QPointer<T>
|
||||
qPointerFromVariant(const QVariant &variant)
|
||||
{
|
||||
return QPointer<T>(qobject_cast<T*>(QtSharedPointer::weakPointerFromVariant_internal(variant).data()));
|
||||
return QPointer<T>(qobject_cast<T*>(QtSharedPointer::weakPointerFromVariant_internal(variant).internalData()));
|
||||
}
|
||||
|
||||
template <class T>
|
||||
|
@ -568,7 +568,7 @@ public:
|
||||
|
||||
#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; }
|
||||
T *data() const noexcept { return internalData(); }
|
||||
#endif
|
||||
|
||||
inline QWeakPointer() noexcept : d(nullptr), value(nullptr) { }
|
||||
@ -678,6 +678,12 @@ public:
|
||||
#else
|
||||
template <class X> friend class QSharedPointer;
|
||||
template <class X> friend class QPointer;
|
||||
template<typename X>
|
||||
friend QWeakPointer<typename std::enable_if<QtPrivate::IsPointerToTypeDerivedFromQObject<X*>::Value, X>::type>
|
||||
qWeakPointerFromVariant(const QVariant &variant);
|
||||
template<typename X>
|
||||
friend QPointer<X>
|
||||
qPointerFromVariant(const QVariant &variant);
|
||||
#endif
|
||||
|
||||
template <class X>
|
||||
@ -701,6 +707,13 @@ public:
|
||||
value = actual;
|
||||
}
|
||||
|
||||
// ### Qt 6: remove users of this API; no one should ever access
|
||||
// a weak pointer's data but the weak pointer itself
|
||||
inline T *internalData() const noexcept
|
||||
{
|
||||
return d == nullptr || d->strongref.load() == 0 ? nullptr : value;
|
||||
}
|
||||
|
||||
Data *d;
|
||||
T *value;
|
||||
};
|
||||
@ -974,11 +987,13 @@ qobject_cast(const QWeakPointer<T> &src)
|
||||
return qSharedPointerObjectCast<typename QtSharedPointer::RemovePointer<X>::Type, T>(src);
|
||||
}
|
||||
|
||||
/// ### Qt 6: make this use toStrongRef() (once support for storing
|
||||
/// non-managed QObjects in QWeakPointer is removed)
|
||||
template<typename T>
|
||||
QWeakPointer<typename std::enable_if<QtPrivate::IsPointerToTypeDerivedFromQObject<T*>::Value, T>::type>
|
||||
qWeakPointerFromVariant(const QVariant &variant)
|
||||
{
|
||||
return QWeakPointer<T>(qobject_cast<T*>(QtSharedPointer::weakPointerFromVariant_internal(variant).data()));
|
||||
return QWeakPointer<T>(qobject_cast<T*>(QtSharedPointer::weakPointerFromVariant_internal(variant).internalData()));
|
||||
}
|
||||
template<typename T>
|
||||
QSharedPointer<typename std::enable_if<QtPrivate::IsPointerToTypeDerivedFromQObject<T*>::Value, T>::type>
|
||||
|
Loading…
Reference in New Issue
Block a user