Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
|
\inmodule QtCore More...
#include <qsharedpointer_impl.h>
Public Types | |
typedef T | element_type |
typedef T | value_type |
typedef value_type * | pointer |
typedef const value_type * | const_pointer |
typedef value_type & | reference |
typedef const value_type & | const_reference |
typedef qptrdiff | difference_type |
Public Member Functions | |
bool | isNull () const noexcept |
Returns true if this object refers to \nullptr. | |
operator bool () const noexcept | |
Returns true if the contained pointer is not \nullptr. | |
bool | operator! () const noexcept |
Returns true if this object refers to \nullptr. | |
Q_NODISCARD_CTOR constexpr | QWeakPointer () noexcept |
~QWeakPointer () | |
Destroys this QWeakPointer object. | |
Q_NODISCARD_CTOR | QWeakPointer (const QWeakPointer &other) noexcept |
Creates a QWeakPointer that holds a weak reference to the pointer referenced by other. | |
Q_NODISCARD_CTOR | QWeakPointer (QWeakPointer &&other) noexcept |
template<class X , IfCompatible< X > = true, IfNotVirtualBase< X > = true> | |
Q_NODISCARD_CTOR | QWeakPointer (QWeakPointer< X > &&other) noexcept |
template<class X , IfCompatible< X > = true, IfVirtualBase< X > = true> | |
Q_NODISCARD_CTOR | QWeakPointer (QWeakPointer< X > &&other) noexcept |
template<class X , IfCompatible< X > = true> | |
QWeakPointer & | operator= (QWeakPointer< X > &&other) noexcept |
QWeakPointer & | operator= (const QWeakPointer &other) noexcept |
Makes this object share other's pointer. | |
void | swap (QWeakPointer &other) noexcept |
Q_NODISCARD_CTOR | QWeakPointer (const QSharedPointer< T > &o) |
Creates a QWeakPointer that holds a weak reference to the pointer referenced by other. | |
QWeakPointer & | operator= (const QSharedPointer< T > &o) |
Makes this object share other's pointer. | |
template<class X , IfCompatible< X > = true> | |
Q_NODISCARD_CTOR | QWeakPointer (const QWeakPointer< X > &o) |
template<class X , IfCompatible< X > = true> | |
QWeakPointer & | operator= (const QWeakPointer< X > &o) |
template<class X , IfCompatible< X > = true> | |
Q_NODISCARD_CTOR | QWeakPointer (const QSharedPointer< X > &o) |
template<class X , IfCompatible< X > = true> | |
QWeakPointer & | operator= (const QSharedPointer< X > &o) |
void | clear () |
Clears this QWeakPointer object, dropping the reference that it may have had to the pointer. | |
QSharedPointer< T > | toStrongRef () const |
Promotes this weak reference to a strong one and returns a QSharedPointer object holding that reference. | |
QSharedPointer< T > | lock () const |
template<class X > | |
bool | operator== (const QWeakPointer< X > &o) const noexcept |
template<class X > | |
bool | operator!= (const QWeakPointer< X > &o) const noexcept |
template<class X > | |
bool | operator== (const QSharedPointer< X > &o) const noexcept |
template<class X > | |
bool | operator!= (const QSharedPointer< X > &o) const noexcept |
template<typename X > | |
bool | owner_before (const QWeakPointer< X > &other) const noexcept |
template<typename X > | |
bool | owner_before (const QSharedPointer< X > &other) const noexcept |
template<typename X > | |
bool | owner_equal (const QWeakPointer< X > &other) const noexcept |
template<typename X > | |
bool | owner_equal (const QSharedPointer< X > &other) const noexcept |
size_t | owner_hash () const noexcept |
Friends | |
struct | QtPrivate::EnableInternalData |
template<class X > | |
class | QSharedPointer |
template<class X > | |
class | QWeakPointer |
Creates a QWeakPointer that points to nothing. | |
template<class X > | |
class | QPointer |
template<typename X > | |
bool | operator== (const QSharedPointer< X > &p1, const QWeakPointer &p2) noexcept |
template<typename X > | |
bool | operator!= (const QSharedPointer< X > &p1, const QWeakPointer &p2) noexcept |
bool | operator== (const QWeakPointer &p, std::nullptr_t) |
bool | operator== (std::nullptr_t, const QWeakPointer &p) |
bool | operator!= (const QWeakPointer &p, std::nullptr_t) |
bool | operator!= (std::nullptr_t, const QWeakPointer &p) |
Related Symbols | |
(Note that these are not member symbols.) | |
template< class T, class X > bool | operator== (const QSharedPointer< T > &ptr1, const QWeakPointer< X > &ptr2) |
Returns true if ptr1 and ptr2 refer to the same pointer. | |
template< class T, class X > bool | operator!= (const QSharedPointer< T > &ptr1, const QWeakPointer< X > &ptr2) |
Returns true if ptr1 and ptr2 refer to distinct pointers. | |
template< class T, class X > bool | operator== (const QWeakPointer< T > &ptr1, const QSharedPointer< X > &ptr2) |
Returns true if ptr1 and ptr2 refer to the same pointer. | |
template< class T > bool | operator== (const QWeakPointer< T > &lhs, std::nullptr_t) |
template< class T > bool | operator== (std::nullptr_t, const QWeakPointer< T > &rhs) |
template< class T > bool | operator!= (const QWeakPointer< T > &lhs, std::nullptr_t) |
template< class T > bool | operator!= (std::nullptr_t, const QWeakPointer< T > &rhs) |
template< class T, class X > bool | operator!= (const QWeakPointer< T > &ptr1, const QSharedPointer< X > &ptr2) |
Returns true if ptr1 and ptr2 refer to distinct pointers. | |
template< class X, class T > QSharedPointer< X > | qSharedPointerCast (const QWeakPointer< T > &other) |
Returns a shared pointer to the pointer held by other, cast to type \tt X. | |
template< class X, class T > QSharedPointer< X > | qSharedPointerDynamicCast (const QWeakPointer< T > &src) |
Returns a shared pointer to the pointer held by src, using a dynamic cast to type \tt X to obtain an internal pointer of the appropriate type. | |
template< class X, class T > QSharedPointer< X > | qSharedPointerConstCast (const QWeakPointer< T > &src) |
Returns a shared pointer to the pointer held by src, cast to type \tt X. | |
template< class X, class T > QSharedPointer< X > | qSharedPointerObjectCast (const QWeakPointer< T > &src) |
The qSharedPointerObjectCast function is for casting a shared pointer. | |
template< class X, class T > QWeakPointer< X > | qWeakPointerCast (const QWeakPointer< T > &src) |
Returns a weak pointer to the pointer held by src, cast to type \tt X. | |
\inmodule QtCore
The QWeakPointer class holds a weak reference to a shared pointer.
The QWeakPointer is an automatic weak reference to a pointer in C++. It cannot be used to dereference the pointer directly, but it can be used to verify if the pointer has been deleted or not in another context.
QWeakPointer objects can only be created by assignment from a QSharedPointer.
It's important to note that QWeakPointer provides no automatic casting operators to prevent mistakes from happening. Even though QWeakPointer tracks a pointer, it should not be considered a pointer itself, since it doesn't guarantee that the pointed object remains valid.
Therefore, to access the pointer that QWeakPointer is tracking, you must first promote it to QSharedPointer and verify if the resulting object is null or not. QSharedPointer guarantees that the object isn't deleted, so if you obtain a non-null object, you may use the pointer. See QWeakPointer::toStrongRef() for an example.
\omit
Definition at line 551 of file qsharedpointer_impl.h.
typedef const value_type* QWeakPointer< T >::const_pointer |
Definition at line 567 of file qsharedpointer_impl.h.
typedef const value_type& QWeakPointer< T >::const_reference |
Definition at line 569 of file qsharedpointer_impl.h.
typedef qptrdiff QWeakPointer< T >::difference_type |
Definition at line 570 of file qsharedpointer_impl.h.
typedef T QWeakPointer< T >::element_type |
Definition at line 564 of file qsharedpointer_impl.h.
typedef value_type* QWeakPointer< T >::pointer |
Definition at line 566 of file qsharedpointer_impl.h.
typedef value_type& QWeakPointer< T >::reference |
Definition at line 568 of file qsharedpointer_impl.h.
typedef T QWeakPointer< T >::value_type |
Definition at line 565 of file qsharedpointer_impl.h.
|
inlineconstexprnoexcept |
Definition at line 577 of file qsharedpointer_impl.h.
|
inline |
Destroys this QWeakPointer object.
The pointer referenced by this object will not be deleted.
Definition at line 578 of file qsharedpointer_impl.h.
References QBasicAtomicInteger< T >::deref(), and QtSharedPointer::ExternalRefCountData::weakref.
|
inlinenoexcept |
Creates a QWeakPointer that holds a weak reference to the pointer referenced by other.
If \tt T is a derived type of the template parameter of this class, QWeakPointer will perform an automatic cast. Otherwise, you will get a compiler error.
Definition at line 581 of file qsharedpointer_impl.h.
References QBasicAtomicInteger< T >::ref(), and QtSharedPointer::ExternalRefCountData::weakref.
|
inlinenoexcept |
Definition at line 584 of file qsharedpointer_impl.h.
References other().
|
inlinenoexcept |
Definition at line 594 of file qsharedpointer_impl.h.
|
inlinenoexcept |
Definition at line 602 of file qsharedpointer_impl.h.
References other().
|
inline |
Creates a QWeakPointer that holds a weak reference to the pointer referenced by other.
If \tt T is a derived type of the template parameter of this class, QWeakPointer will perform an automatic cast. Otherwise, you will get a compiler error.
Definition at line 631 of file qsharedpointer_impl.h.
References QBasicAtomicInteger< T >::ref(), and QtSharedPointer::ExternalRefCountData::weakref.
|
inline |
Definition at line 641 of file qsharedpointer_impl.h.
References o.
|
inline |
Definition at line 655 of file qsharedpointer_impl.h.
References o.
|
inline |
Clears this QWeakPointer object, dropping the reference that it may have had to the pointer.
Definition at line 665 of file qsharedpointer_impl.h.
References QWeakPointer< T >::QWeakPointer.
|
inlinenoexcept |
Returns true
if this object refers to \nullptr.
Note that, due to the nature of weak references, the pointer that QWeakPointer references can become \nullptr at any moment, so the value returned from this function can change from false to true from one call to the next.
Definition at line 572 of file qsharedpointer_impl.h.
References QBasicAtomicInteger< T >::loadRelaxed(), and QtSharedPointer::ExternalRefCountData::strongref.
Referenced by QWeakPointer< T >::operator bool(), and QWeakPointer< T >::operator!().
|
inline |
Same as toStrongRef().
This function is provided for API compatibility with std::weak_ptr.
Definition at line 669 of file qsharedpointer_impl.h.
References QWeakPointer< T >::toStrongRef().
|
inlineexplicitnoexcept |
Returns true
if the contained pointer is not \nullptr.
This function is suitable for use in \tt if-constructs, like:
Note that, due to the nature of weak references, the pointer that QWeakPointer references can become \nullptr at any moment, so the value returned from this function can change from true to false from one call to the next.
Definition at line 573 of file qsharedpointer_impl.h.
References QWeakPointer< T >::isNull().
|
inlinenoexcept |
Returns true
if this object refers to \nullptr.
This function is suitable for use in \tt if-constructs, like:
Note that, due to the nature of weak references, the pointer that QWeakPointer references can become \nullptr at any moment, so the value returned from this function can change from false to true from one call to the next.
Definition at line 574 of file qsharedpointer_impl.h.
References QWeakPointer< T >::isNull().
|
inlinenoexcept |
Definition at line 684 of file qsharedpointer_impl.h.
References o.
|
inlinenoexcept |
Definition at line 676 of file qsharedpointer_impl.h.
References o.
|
inline |
Makes this object share other's pointer.
The current pointer reference is discarded but is not deleted.
If \tt T is a derived type of the template parameter of this class, QWeakPointer will perform an automatic cast. Otherwise, you will get a compiler error.
Definition at line 633 of file qsharedpointer_impl.h.
References o.
|
inline |
Definition at line 659 of file qsharedpointer_impl.h.
References o.
|
inlinenoexcept |
Makes this object share other's pointer.
The current pointer reference is discarded but is not deleted.
If \tt T is a derived type of the template parameter of this class, QWeakPointer will perform an automatic cast. Otherwise, you will get a compiler error.
Definition at line 617 of file qsharedpointer_impl.h.
References copy(), other(), and QWeakPointer< T >::swap().
|
inline |
Definition at line 645 of file qsharedpointer_impl.h.
References o.
|
inlinenoexcept |
Definition at line 610 of file qsharedpointer_impl.h.
References other(), and QWeakPointer< T >::swap().
|
inlinenoexcept |
Definition at line 680 of file qsharedpointer_impl.h.
References o.
|
inlinenoexcept |
Definition at line 672 of file qsharedpointer_impl.h.
References o.
|
inlinenoexcept |
Definition at line 707 of file qsharedpointer_impl.h.
References other().
|
inlinenoexcept |
Returns true
if and only if this smart pointer precedes other in an implementation-defined owner-based ordering. The ordering is such that two smart pointers are considered equivalent if they are both empty or if they both own the same object (even if their apparent type and pointer are different).
Definition at line 704 of file qsharedpointer_impl.h.
References other().
|
inlinenoexcept |
Definition at line 714 of file qsharedpointer_impl.h.
References other().
|
inlinenoexcept |
Returns true
if and only if this smart pointer and other share ownership.
Definition at line 711 of file qsharedpointer_impl.h.
References other().
|
inlinenoexcept |
Returns a owner-based hash value for this smart pointer object. Smart pointers that compare equal (as per {owner_equal}) will have an identical owner-based hash.
Definition at line 717 of file qsharedpointer_impl.h.
|
inlinenoexcept |
Swaps this weak pointer instance with other. This function is very fast and never fails.
Definition at line 624 of file qsharedpointer_impl.h.
References other(), and qt_ptr_swap().
Referenced by QWeakPointer< T >::operator=(), and QWeakPointer< T >::operator=().
|
inline |
Promotes this weak reference to a strong one and returns a QSharedPointer object holding that reference.
When promoting to QSharedPointer, this function verifies if the object has been deleted already or not. If it hasn't, this function increases the reference count to the shared object, thus ensuring that it will not get deleted.
Since this function can fail to obtain a valid strong reference to the shared object, you should always verify if the conversion succeeded, by calling QSharedPointer::isNull() on the returned object.
For example, the following code promotes a QWeakPointer that was held to a strong reference and, if it succeeded, it prints the value of the integer that was held:
Definition at line 667 of file qsharedpointer_impl.h.
Referenced by QWeakPointer< T >::lock(), and QQmlJSMetaParameter::type().
Creates a QWeakPointer that points to nothing.
Definition at line 723 of file qsharedpointer_impl.h.
Referenced by QWeakPointer< T >::clear().
|
related |
Returns true
if ptr1 and ptr2 refer to distinct pointers.
If ptr2's template parameter is different from ptr1's, QSharedPointer will attempt to perform an automatic \tt static_cast to ensure that the pointers being compared are equal. If ptr2's template parameter is not a base or a derived type from ptr1's, you will get a compiler error.
|
friend |
Definition at line 691 of file qsharedpointer_impl.h.
|
friend |
Returns true
if lhs refers to a valid (i.e. non-null) pointer.
Definition at line 698 of file qsharedpointer_impl.h.
|
related |
Returns true
if lhs refers to a valid (i.e. non-null) pointer.
|
related |
Returns true
if ptr1 and ptr2 refer to distinct pointers.
If ptr2's template parameter is different from ptr1's, QSharedPointer will attempt to perform an automatic \tt static_cast to ensure that the pointers being compared are equal. If ptr2's template parameter is not a base or a derived type from ptr1's, you will get a compiler error.
|
friend |
Returns true
if rhs refers to a valid (i.e. non-null) pointer.
Definition at line 700 of file qsharedpointer_impl.h.
|
related |
Returns true
if rhs refers to a valid (i.e. non-null) pointer.
|
related |
Returns true
if ptr1 and ptr2 refer to the same pointer.
If ptr2's template parameter is different from ptr1's, QSharedPointer will attempt to perform an automatic \tt static_cast to ensure that the pointers being compared are equal. If ptr2's template parameter is not a base or a derived type from ptr1's, you will get a compiler error.
|
friend |
Definition at line 688 of file qsharedpointer_impl.h.
|
friend |
Returns true
if lhs refers to \nullptr.
Definition at line 694 of file qsharedpointer_impl.h.
|
related |
|
related |
Returns true
if ptr1 and ptr2 refer to the same pointer.
If ptr2's template parameter is different from ptr1's, QSharedPointer will attempt to perform an automatic \tt static_cast to ensure that the pointers being compared are equal. If ptr2's template parameter is not a base or a derived type from ptr1's, you will get a compiler error.
|
friend |
Returns true
if rhs refers to \nullptr.
Definition at line 696 of file qsharedpointer_impl.h.
|
related |
Definition at line 724 of file qsharedpointer_impl.h.
Definition at line 722 of file qsharedpointer_impl.h.
|
related |
Returns a shared pointer to the pointer held by other, cast to type \tt X.
The types \tt T and \tt X must belong to one hierarchy for the \tt static_cast to succeed.
The other object is converted first to a strong reference. If that conversion fails (because the object it's pointing to has already been deleted), this function returns a null QSharedPointer.
Note that \tt X must have the same cv-qualifiers (\tt const and \tt volatile) that \tt T has, or the code will fail to compile. Use qSharedPointerConstCast to cast away the constness.
Definition at line 877 of file qsharedpointer_impl.h.
|
related |
Returns a shared pointer to the pointer held by src, cast to type \tt X.
The types \tt T and \tt X must belong to one hierarchy for the \tt const_cast to succeed. The \tt const and \tt volatile differences between \tt T and \tt X are ignored.
The src object is converted first to a strong reference. If that conversion fails (because the object it's pointing to has already been deleted), this function returns a null QSharedPointer.
Definition at line 903 of file qsharedpointer_impl.h.
|
related |
Returns a shared pointer to the pointer held by src, using a dynamic cast to type \tt X to obtain an internal pointer of the appropriate type.
If the \tt dynamic_cast fails, the object returned will be null.
The src object is converted first to a strong reference. If that conversion fails (because the object it's pointing to has already been deleted), this function also returns a null QSharedPointer.
Note that \tt X must have the same cv-qualifiers (\tt const and \tt volatile) that \tt T has, or the code will fail to compile. Use qSharedPointerConstCast to cast away the constness.
Definition at line 891 of file qsharedpointer_impl.h.
|
related |
The qSharedPointerObjectCast function is for casting a shared pointer.
Returns a shared pointer to the pointer held by src, using a \l qobject_cast() to type \tt X to obtain an internal pointer of the appropriate type. If the \tt qobject_cast fails, the object returned will be null.
The src object is converted first to a strong reference. If that conversion fails (because the object it's pointing to has already been deleted), this function also returns a null QSharedPointer.
Note that \tt X must have the same cv-qualifiers (\tt const and \tt volatile) that \tt T has, or the code will fail to compile. Use qSharedPointerConstCast to cast away the constness.
Definition at line 923 of file qsharedpointer_impl.h.
|
friend |
Definition at line 721 of file qsharedpointer_impl.h.
|
related |
Returns a weak pointer to the pointer held by src, cast to type \tt X.
The types \tt T and \tt X must belong to one hierarchy for the \tt static_cast to succeed.
Note that \tt X must have the same cv-qualifiers (\tt const and \tt volatile) that \tt T has, or the code will fail to compile. Use qSharedPointerConstCast to cast away the constness.