![]() |
CopperSpice API
1.8.1
|
Holds a weak reference to a shared pointer. More...
Public Typedefs | |
typedef const value_type * | const_pointer |
typedef const value_type & | const_reference |
typedef qptrdiff | difference_type |
typedef T | element_type |
typedef value_type * | pointer |
typedef value_type & | reference |
typedef T | value_type |
Public Methods | |
QWeakPointer () | |
QWeakPointer (const QSharedPointer< T > &other) | |
QWeakPointer (const QWeakPointer< T > &other) | |
template<class X > | |
QWeakPointer (const QWeakPointer< X > &other) | |
~QWeakPointer () | |
void | clear () |
T * | data () const |
bool | isNull () const |
operator RestrictedBool () const | |
bool | operator! () const |
template<class X > | |
bool | operator!= (const QSharedPointer< X > &other) const |
template<class X > | |
bool | operator!= (const QWeakPointer< X > &other) const |
QWeakPointer< T > & | operator= (const QSharedPointer< T > &other) |
QWeakPointer< T > & | operator= (const QWeakPointer< T > &other) |
template<class X > | |
QWeakPointer< T > & | operator= (const QWeakPointer< X > &other) |
template<class X > | |
bool | operator== (const QSharedPointer< X > &other) const |
template<class X > | |
bool | operator== (const QWeakPointer< X > &other) const |
QSharedPointer< T > | toStrongRef () const |
Friends | |
template<class X > | |
class | QPointer |
template<class X > | |
class | QSharedPointer |
Related Functions | |
These are not member functions | |
bool | operator!= (const QSharedPointer< T > &ptr1, const QWeakPointer< T > &ptr2) |
bool | operator!= (const QWeakPointer< T > &ptr1, const QSharedPointer< X > &ptr2) |
bool | operator== (const QSharedPointer< T > &ptr1, const QWeakPointer< T > &ptr2) |
bool | operator== (const QWeakPointer< T > &ptr1, const QSharedPointer< T > &ptr2) |
QSharedPointer< X > | qSharedPointerCast (const QWeakPointer< T > &other) |
QSharedPointer< X > | qSharedPointerConstCast (const QWeakPointer< T > &other) |
QSharedPointer< X > | qSharedPointerDynamicCast (const QWeakPointer< T > &other) |
QSharedPointer< X > | qSharedPointerObjectCast (const QWeakPointer< T > &other) |
QWeakPointer< X > | qWeakPointerCast (const QWeakPointer< T > &other) |
The QWeakPointer class holds a weak reference to a shared pointer. It can not 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 is 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 does not guarantee that the pointed object remains valid.
Therefore, to access the pointer which QWeakPointer is tracking you must first promote it to QSharedPointer and verify if the resulting object is or is not null. QSharedPointer guarantees the object is not deleted. So if you obtain a non-null object you may use the pointer. Refer to QWeakPointer::toStrongRef() for an example.
QWeakPointer also provides the QWeakPointer::data() method which returns the tracked pointer without ensuring if 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. T) and the cost of creating a QSharedPointer using toStrongRef() is too high.
That function can also be used to obtain the tracked pointer for QWeakPointers that can not be promoted to QSharedPointer, such as those created directly from a QObject pointer (not via QSharedPointer).
QWeakPointer< T >::const_pointer |
Typedef for const T *.
QWeakPointer< T >::const_reference |
Typedef for T &.
QWeakPointer< T >::difference_type |
Typedef for integral type used to represent the distance between two elements.
QWeakPointer< T >::element_type |
Typedef for T.
QWeakPointer< T >::pointer |
Typedef for T *.
QWeakPointer< T >::reference |
Typedef for T &.
QWeakPointer< T >::value_type |
Typedef for T.
|
inline |
Creates a QWeakPointer that points to nothing.
|
inline |
Destroys this QWeakPointer object. The pointer referenced by this object will not be deleted.
|
inline |
Creates a QWeakPointer that holds a weak reference to the pointer referenced by other.
|
inline |
Creates a QWeakPointer that holds a weak reference to the pointer referenced by other.
|
inline |
Creates a QWeakPointer that holds a weak reference to the pointer referenced by other.
If X
inherits from the template parameter of this class, QWeakPointer will perform an automatic cast.
|
inline |
Clears this QWeakPointer object, dropping the reference that it may have had to the pointer.
|
inline |
Returns the value of the pointer being tracked by this QWeakPointer, without ensuring that it can not get deleted. To have that guarantee, use toStrongRef(), which returns a QSharedPointer object. If this function can determine that the pointer has already been deleted, it returns 0.
It is ok to obtain the value of the pointer and using that value itself, like for example in debugging statements:
However, dereferencing the pointer is only allowed if you can guarantee by external means that the pointer does not get deleted. For example, if you can be certain that no other thread can delete it, nor the functions that you may call.
If that is the case, then the following code is valid:
|
inline |
Returns true if this object is holding a reference to a null pointer.
De to the nature of weak references, the pointer that QWeakPointer references can become null at any moment, so the value returned from this method can change from false to true from one call to the next.
|
inline |
Returns true if this object is not null. This method is suitable for use in if-constructs
. Due to the nature of weak references, a QWeakPointer can become null at any moment.
|
inline |
Returns true if this object is null. This method is suitable for use in if-constructs
. Due to the nature of weak references, a QWeakPointer can become null at any moment.
|
inline |
Returns true if other is not equal to this weak pointer, otherwise returns false.
|
inline |
Returns true if other is not equal to this weak pointer, otherwise returns false.
|
inline |
Copy assigns from other and returns a reference to this object.
|
inline |
Copy assigns from other and returns a reference to this object.
|
inline |
Copy assigns from other and returns a reference to this object.
|
inline |
Returns true if other is equal to this weak pointer, otherwise returns false.
|
inline |
Returns true if other is equal to this weak pointer, otherwise returns false.
|
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 has not, this method increases the reference count to the shared object, thus ensuring that it will not get deleted.
Since this method 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:
|
related |
Returns true if ptr1 and ptr2 do not point to the same object.
|
related |
Returns true if ptr1 and ptr2 do not point to the same object
|
related |
Returns true if ptr1 and ptr2 point to the same object.
|
related |
Returns true if ptr1 and ptr2 point to the same object.
|
related |
Returns a shared pointer to the pointer in other cast to type X. The types T and X must be compatable types. The other object is converted first to a strong reference. If the conversion fails this function returns a null QSharedPointer.
The type of X must have the same cv-qualifiers as the type for T.
|
related |
Returns a shared pointer to the pointer in other cast to type X. The types T and X must be compatable types. The other object is converted first to a strong reference. If the conversion fails this function returns a null QSharedPointer.
The const and volatile differences between T and X are ignored.
|
related |
Returns a shared pointer to the pointer in other cast to type X. The types T and X must be compatable types. The other object is converted first to a strong reference. If the conversion fails this function returns a null QSharedPointer.
The type of X must have the same cv-qualifiers as the type for T.
|
related |
Returns a shared pointer to the pointer in other cast to type X. The types T and X must be compatable types. The other object is converted first to a strong reference. If the conversion fails this function returns a null QSharedPointer.
The type of X must have the same cv-qualifiers as the type for T.
|
related |
Returns a shared pointer to the pointer in other cast to type X. The types T and X must be compatable types. The other object is converted first to a strong reference. If the conversion fails this function returns a null QSharedPointer.
The type of X must have the same cv-qualifiers as the type for T.