CopperSpice API
1.9.2
|
Stores a weak pointer to a potentially shared object. More...
Public Typedefs | |
using | element_type = typename std::shared_ptr< T >::element_type |
using | ElementType = element_type |
using | pointer = element_type * |
using | Pointer = pointer |
Public Methods | |
QWeakPointer () | |
template<typename U > | |
QWeakPointer (const QSharedPointer< U > &p) | |
QWeakPointer (const QWeakPointer< T > &other) | |
template<typename U > | |
QWeakPointer (const QWeakPointer< U > &other) | |
QWeakPointer (QWeakPointer< T > &&other) | |
QWeakPointer (T *p) | |
~QWeakPointer () | |
void | clear () noexcept |
Pointer | data () const noexcept |
bool | expired () const noexcept |
bool | isNull () const |
operator bool () const noexcept | |
bool | operator! () const |
template<typename U > | |
QWeakPointer & | operator= (const QSharedPointer< U > &p) noexcept |
QWeakPointer & | operator= (const QWeakPointer< T > &other) |
QWeakPointer & | operator= (QWeakPointer< T > &&other) |
template<typename U > | |
bool | owner_before (const QSharedPointer< U > &p) const noexcept |
template<typename U > | |
bool | owner_before (const QWeakPointer< U > &p) const noexcept |
QSharedPointer< T > | toStrongRef () const noexcept |
Related Functions | |
These are not member functions | |
bool | operator!= (const QSharedPointer< T1 > &ptr1, const QWeakPointer< T2 > &ptr2) |
bool | operator!= (const QWeakPointer< T > &ptr1, std::nullptr_t) |
bool | operator!= (const QWeakPointer< T1 > &ptr1, const QSharedPointer< T2 > &ptr2) |
bool | operator!= (std::nullptr_t, const QWeakPointer< T > &ptr2) |
bool | operator== (const QSharedPointer< T1 > &ptr1, const QWeakPointer< T2 > &ptr2) |
bool | operator== (const QWeakPointer< T > &ptr1, std::nullptr_t) |
bool | operator== (const QWeakPointer< T1 > &ptr1, const QSharedPointer< T2 > &ptr2) |
bool | operator== (std::nullptr_t, const QWeakPointer< T > &ptr2) |
The QWeakPointer class stores a weak pointer to a potentially shared object. A weak pointer is a smart pointer which does take ownership or manage the lifetime of the shared object. A CsWeakPointer can only be created by calling QSharedPointer::toWeakRef() or using the constructor in QWeakPointer which accepts a QSharedPointer.
To access the object which QWeakPointer points to, convert it to QSharedPointer and ensure the shared pointer is not a nullptr. If the shared pointer is not a nullptr, the object will not be deleted while the shared pointer is in scope.
QWeakPointer also provides a data() method which returns a raw pointer to the object. This method should only be used if your code can absolutely guarantee the object will not get deleted.
QWeakPointer< T >::element_type |
Typedef for std::weak_ptr<T>::element_type.
QWeakPointer< T >::ElementType |
Typedef for element_type.
QWeakPointer< T >::pointer |
Typedef for element_type *.
QWeakPointer< T >::Pointer |
Typedef for pointer.
QWeakPointer< T >::QWeakPointer | ( | ) |
Creates a new QWeakPointer which contains a nullptr.
QWeakPointer< T >::QWeakPointer | ( | const QWeakPointer< U > & | other | ) |
Creates a new QWeakPointer which points to the same object as other. This constructor is only available if U* can be converted to a T*.
QWeakPointer< T >::QWeakPointer | ( | T * | p | ) |
Creates a new QWeakPointer which points to p. This constructor is only available if T is a class which inherits from QObject.
This constructor uses the internal shared pointer in QObject pointed to by p, to create the new weak pointer.
QWeakPointer< T >::~QWeakPointer | ( | ) |
Destroys this QWeakPointer object. The pointer referenced by this object will not be deleted.
QWeakPointer< T >::QWeakPointer | ( | const QWeakPointer< T > & | other | ) |
Copy constructs a new QWeakPointer from other.
QWeakPointer< T >::QWeakPointer | ( | QWeakPointer< T > && | other | ) |
Move constructs a new QWeakPointer from other.
QWeakPointer< T >::QWeakPointer | ( | const QSharedPointer< U > & | p | ) |
Creates a new QWeakPointer which contains a weak reference to the shared pointer p.
|
noexcept |
Sets this QWeakPointer object to a nullptr.
|
noexcept |
Returns the value of the raw pointer in this QWeakPointer. If the object has already been deleted this method will return a nullptr. Dereferencing this raw pointer is only permissible if the code can absolutely guarantee the object will not be deleted before the dereference occurs.
|
noexcept |
Equivalent to calling isNull().
bool QWeakPointer< T >::isNull | ( | ) | const |
Returns true if this object contains a reference to a null pointer. Since the object the QWeakPointer references can be deleted at any time, a value of true does not guarantee the object is still alive after calling this method.
|
explicitnoexcept |
Returns true if the current QWeakPointer is not a nullptr. This method is called when a shared pointer is used in an "if statement" or another context where a boolean value is expected. Since this method is explicit it is not possible to assign a QSharedPointer to a boolean.
bool QWeakPointer< T >::operator! | ( | ) | const |
Returns true if this object is a nullptr. This method is called when a shared pointer is used in an "if statement" or another context where a boolean value is expected.
|
noexcept |
Copy assigns from the shared pointer p and returns a reference to this object.
QWeakPointer & QWeakPointer< T >::operator= | ( | const QWeakPointer< T > & | other | ) |
Copy assigns from other and returns a reference to this object.
QWeakPointer & QWeakPointer< T >::operator= | ( | QWeakPointer< T > && | other | ) |
Move assigns from other and returns a reference to this object.
|
noexcept |
Returns true if the current pointer is less than p, otherwise returns false.
|
noexcept |
Returns true if the current pointer is less than p, otherwise returns false.
|
noexcept |
Converts the current weak pointer to a shared pointer and returns the QSharedPointer. This method can fail if the object the QWeakPointer is pointing to has been deleted. To prevent undefined behavior verify the return value by calling QSharedPointer::isNull() before dereferencing.
|
related |
Returns true if ptr1 and ptr2 do not point to the same object.
|
related |
Returns true if ptr1 is not a nullptr, otherwise returns false.
|
related |
Returns true if ptr1 and ptr2 do not point to the same object.
|
related |
Returns true if ptr2 is not a nullptr, otherwise returns false.
|
related |
Returns true if ptr1 and ptr2 point to the same object.
|
related |
Returns true if ptr1 is a nullptr, otherwise returns false.
|
related |
Returns true if ptr1 and ptr2 point to the same object.
|
related |
Returns true if ptr2 is a nullptr, otherwise returns false.