![]() |
Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
\inmodule QtCore More...
#include <qsharedpointer_impl.h>
Public Types | |
| typedef T | Type |
| 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 | |
| T * | data () const noexcept |
| Returns the value of the pointer referenced by this object. | |
| T * | get () const noexcept |
| 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. | |
| T & | operator* () const |
| Provides access to the shared pointer's members. | |
| T * | operator-> () const noexcept |
| Provides access to the shared pointer's members. | |
| Q_NODISCARD_CTOR constexpr | QSharedPointer () noexcept |
| ~QSharedPointer () | |
| Destroys this QSharedPointer object. | |
| Q_NODISCARD_CTOR constexpr | QSharedPointer (std::nullptr_t) noexcept |
| template<class X, IfCompatible< X > = true> | |
| Q_NODISCARD_CTOR | QSharedPointer (X *ptr) |
| Creates a QSharedPointer that points to ptr. | |
| template<class X, typename Deleter, IfCompatible< X > = true> | |
| Q_NODISCARD_CTOR | QSharedPointer (X *ptr, Deleter deleter) |
| Creates a QSharedPointer that points to ptr. | |
| template<typename Deleter> | |
| Q_NODISCARD_CTOR | QSharedPointer (std::nullptr_t, Deleter deleter) |
| Q_NODISCARD_CTOR | QSharedPointer (const QSharedPointer &other) noexcept |
| Creates a QSharedPointer object that shares other's pointer. | |
| QSharedPointer & | operator= (const QSharedPointer &other) noexcept |
| Makes this object share other's pointer. | |
| Q_NODISCARD_CTOR | QSharedPointer (QSharedPointer &&other) noexcept |
| Move-constructs a QSharedPointer instance, making it point at the same object that other was pointing to. | |
| template<class X, IfCompatible< X > = true> | |
| Q_NODISCARD_CTOR | QSharedPointer (QSharedPointer< X > &&other) noexcept |
| Move-constructs a QSharedPointer instance, making it point at the same object that other was pointing to. | |
| template<class X, IfCompatible< X > = true> | |
| QSharedPointer & | operator= (QSharedPointer< X > &&other) noexcept |
| Move-assigns other to this QSharedPointer instance. | |
| template<class X, IfCompatible< X > = true> | |
| Q_NODISCARD_CTOR | QSharedPointer (const QSharedPointer< X > &other) noexcept |
| template<class X, IfCompatible< X > = true> | |
| QSharedPointer & | operator= (const QSharedPointer< X > &other) |
| template<class X, IfCompatible< X > = true> | |
| Q_NODISCARD_CTOR | QSharedPointer (const QWeakPointer< X > &other) |
| template<class X, IfCompatible< X > = true> | |
| QSharedPointer< T > & | operator= (const QWeakPointer< X > &other) |
| void | swap (QSharedPointer &other) noexcept |
| void | reset () |
| void | reset (T *t) |
| template<typename Deleter> | |
| void | reset (T *t, Deleter deleter) |
| template<class X> | |
| QSharedPointer< X > | staticCast () const & |
| template<class X> | |
| QSharedPointer< X > | staticCast () && |
| template<class X> | |
| QSharedPointer< X > | dynamicCast () const & |
| template<class X> | |
| QSharedPointer< X > | dynamicCast () && |
| template<class X> | |
| QSharedPointer< X > | constCast () const & |
| template<class X> | |
| QSharedPointer< X > | constCast () && |
| template<class X> | |
| QSharedPointer< X > | objectCast () const & |
| template<class X> | |
| QSharedPointer< X > | objectCast () && |
| void | clear () |
| Clears this QSharedPointer object, dropping the reference that it may have had to the pointer. | |
| QWeakPointer< T > | toWeakRef () const |
| Returns a weak reference object that shares the pointer referenced by this object. | |
| template<typename X> | |
| bool | owner_before (const QSharedPointer< X > &other) const noexcept |
| template<typename X> | |
| bool | owner_before (const QWeakPointer< X > &other) const noexcept |
| template<typename X> | |
| bool | owner_equal (const QSharedPointer< X > &other) const noexcept |
| template<typename X> | |
| bool | owner_equal (const QWeakPointer< X > &other) const noexcept |
| size_t | owner_hash () const noexcept |
Static Public Member Functions | |
| template<typename... Args> | |
| static QSharedPointer | create (Args &&...arguments) |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
Friends | |
| template<class X> | |
| class | QSharedPointer |
| Creates a QSharedPointer that is null (the object is holding a reference to \nullptr). | |
| template<class X> | |
| class | QWeakPointer |
| template<typename X> | |
| bool | comparesEqual (const QSharedPointer &lhs, const QSharedPointer< X > &rhs) noexcept |
| template<typename X> | |
| Qt::strong_ordering | compareThreeWay (const QSharedPointer &lhs, const QSharedPointer< X > &rhs) noexcept |
| template<typename X> | |
| Qt::strong_ordering | compareThreeWay (const QSharedPointer &lhs, X *rhs) noexcept |
| bool | comparesEqual (const QSharedPointer &lhs, std::nullptr_t) noexcept |
| Qt::strong_ordering | compareThreeWay (const QSharedPointer &lhs, std::nullptr_t) noexcept |
| template<class X, class Y> | |
| QSharedPointer< X > | QtSharedPointer::copyAndSetPointer (X *ptr, const QSharedPointer< Y > &src) |
| template<class X, class Y> | |
| QSharedPointer< X > | QtSharedPointer::movePointer (X *ptr, QSharedPointer< Y > &&src) |
Related Symbols | |
(Note that these are not member symbols.) | |
| template< typename T > QDebug | operator<< (QDebug debug, const QSharedPointer< T > &ptr) |
| template< class T, class X > bool | operator!= (const QSharedPointer< T > &lhs, const QSharedPointer< X > &rhs) |
Returns true if lhs and rhs refer to distinct pointers. | |
| template< class T, class X > bool | operator== (const QSharedPointer< T > &lhs, const X *rhs) |
Returns true if lhs and rhs refer to the same pointer. | |
| template< class T, class X > bool | operator!= (const QSharedPointer< T > &lhs, const X *rhs) |
Returns true if lhs and rhs refer to distinct pointers. | |
| template< class T, class X > bool | operator== (const T *lhs, const QSharedPointer< X > &rhs) |
Returns true if the pointer lhs is the same pointer as that referenced by rhs. | |
| template< class T, class X > bool | operator!= (const T *lhs, const QSharedPointer< X > &rhs) |
Returns true if the pointer lhs is not the same pointer as that referenced by rhs. | |
| template< class T > bool | operator== (const QSharedPointer< T > &lhs, std::nullptr_t) |
| template< class T > bool | operator== (std::nullptr_t, const QSharedPointer< T > &rhs) |
| template< class T > bool | operator!= (const QSharedPointer< T > &lhs, std::nullptr_t) |
| template< class T > bool | operator!= (std::nullptr_t, const QSharedPointer< T > &rhs) |
| template< class X, class T > QSharedPointer< X > | qSharedPointerCast (const QSharedPointer< T > &other) |
| Returns a shared pointer to the pointer held by other, cast to type \tt X. | |
| template< class X, class T > QSharedPointer< X > | qSharedPointerCastqSharedPointerCast (QSharedPointer< T > &&other)(const QSharedPointer< T > &other) |
| template< class X, class T > QSharedPointer< X > | qSharedPointerDynamicCast (const QSharedPointer< 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 > | qSharedPointerDynamicCastqSharedPointerDynamicCast (QSharedPointer< T > &&src)(const QSharedPointer< T > &src) |
| template< class X, class T > QSharedPointer< X > | qSharedPointerConstCast (const QSharedPointer< T > &src) |
| Returns a shared pointer to the pointer held by src, cast to type \tt X. | |
| template< class X, class T > QSharedPointer< X > | qSharedPointerConstCastqSharedPointerConstCast (QSharedPointer< T > &&src)(const QSharedPointer< T > &src) |
| template< class X, class T > QSharedPointer< X > | qSharedPointerObjectCast (const QSharedPointer< T > &src) |
| The qSharedPointerObjectCast function is for casting a shared pointer. | |
| template< class X, class T > QSharedPointer< X > | qSharedPointerObjectCastqSharedPointerObjectCast (QSharedPointer< T > &&src)(const QSharedPointer< T > &src) |
| template< class X, class T > std::shared_ptr< X > | qSharedPointerObjectCast (const std::shared_ptr< T > &src) |
| template< class X, class T > std::shared_ptr< X > | qobject_pointer_cast (const std::shared_ptr< T > &src) |
| template< class X, class T > std::shared_ptr< X > | qSharedPointerObjectCast (std::shared_ptr< T > &&src) |
| template< class X, class T > std::shared_ptr< X > | qobject_pointer_cast (std::shared_ptr< T > &&src) |
\inmodule QtCore
The QSharedPointer class holds a strong reference to a shared pointer.
\reentrant
\compares strong \compareswith strong QSharedPointer<X> X* std::nullptr_t Where X and T are compatible types, which means that they are either the same or one is a base type of the other. \endcompareswith
The QSharedPointer is an automatic, shared pointer in C++, where the template parameter T specifies the type of the pointer being managed. It behaves exactly like a normal pointer for normal purposes, including respect for constness.
QSharedPointer will delete the pointer it is holding when it goes out of scope, provided no other QSharedPointer objects are referencing it.
A QSharedPointer object can be created from a normal pointer, another QSharedPointer object or by promoting a QWeakPointer object to a strong reference.
Definition at line 268 of file qsharedpointer_impl.h.
| typedef const value_type* QSharedPointer< T >::const_pointer |
Definition at line 279 of file qsharedpointer_impl.h.
| typedef const value_type& QSharedPointer< T >::const_reference |
Definition at line 281 of file qsharedpointer_impl.h.
| typedef qptrdiff QSharedPointer< T >::difference_type |
Definition at line 282 of file qsharedpointer_impl.h.
| typedef T QSharedPointer< T >::element_type |
Definition at line 276 of file qsharedpointer_impl.h.
| typedef value_type* QSharedPointer< T >::pointer |
Definition at line 278 of file qsharedpointer_impl.h.
| typedef value_type& QSharedPointer< T >::reference |
Definition at line 280 of file qsharedpointer_impl.h.
| typedef T QSharedPointer< T >::Type |
Definition at line 275 of file qsharedpointer_impl.h.
| typedef T QSharedPointer< T >::value_type |
Definition at line 277 of file qsharedpointer_impl.h.
|
inlineconstexprnoexcept |
Definition at line 293 of file qsharedpointer_impl.h.
|
inline |
Destroys this QSharedPointer object.
If it is the last reference to the pointer stored, this will delete the pointer as well.
Definition at line 294 of file qsharedpointer_impl.h.
|
inlineconstexprnoexcept |
Creates a QSharedPointer that is null. This is equivalent to the QSharedPointer default constructor.
Definition at line 297 of file qsharedpointer_impl.h.
|
inlineexplicit |
Creates a QSharedPointer that points to ptr.
The pointer ptr becomes managed by this QSharedPointer and must not be passed to another QSharedPointer object or deleted outside this object.
Since Qt 5.8, when the last reference to this QSharedPointer gets destroyed, ptr will be deleted by calling X's destructor (even if X is not the same as QSharedPointer's template parameter T). Previously, the destructor for T was called.
Definition at line 301 of file qsharedpointer_impl.h.
|
inline |
Creates a QSharedPointer that points to ptr.
The pointer ptr becomes managed by this QSharedPointer and must not be passed to another QSharedPointer object or deleted outside this object.
The deleter parameter d specifies the custom deleter for this object. The custom deleter is called, instead of the operator delete(), when the strong reference count drops to 0. This is useful, for instance, for calling \l {QObject::}{deleteLater()} on a QObject instead:
Note that the custom deleter function will be called with a pointer to type X, even if the QSharedPointer template parameter T is not the same.
It is also possible to specify a member function directly, as in:
Definition at line 306 of file qsharedpointer_impl.h.
|
inline |
Creates a QSharedPointer that is null. This is equivalent to the QSharedPointer default constructor.
The deleter parameter d specifies the custom deleter for this object. The custom deleter is called, instead of the operator delete(), when the strong reference count drops to 0.
Definition at line 311 of file qsharedpointer_impl.h.
|
inlinenoexcept |
Creates a QSharedPointer object that shares other's pointer.
If \tt T is a derived type of the template parameter of this class, QSharedPointer will perform an automatic cast. Otherwise, you will get a compiler error.
Definition at line 315 of file qsharedpointer_impl.h.
|
inlinenoexcept |
Move-constructs a QSharedPointer instance, making it point at the same object that other was pointing to.
Definition at line 324 of file qsharedpointer_impl.h.
|
inlinenoexcept |
Move-constructs a QSharedPointer instance, making it point at the same object that other was pointing to.
\constraints {X*} implicitly converts to {T*}.
Definition at line 334 of file qsharedpointer_impl.h.
|
inlinenoexcept |
Definition at line 351 of file qsharedpointer_impl.h.
|
inline |
Definition at line 364 of file qsharedpointer_impl.h.
|
inline |
Clears this QSharedPointer object, dropping the reference that it may have had to the pointer.
If this was the last reference, then the pointer itself will be deleted.
Definition at line 431 of file qsharedpointer_impl.h.
|
inline |
Definition at line 412 of file qsharedpointer_impl.h.
|
inline |
Definition at line 406 of file qsharedpointer_impl.h.
|
inlinestaticnodiscard |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Creates a QSharedPointer object and allocates a new item of type \tt T. The QSharedPointer internals and the object are allocated in one single memory allocation, which could help reduce memory fragmentation in a long-running application.
This function will attempt to call a constructor for type \tt T that can accept all the arguments passed (args). Arguments will be perfectly-forwarded.
Definition at line 436 of file qsharedpointer_impl.h.
|
inlinenoexcept |
Returns the value of the pointer referenced by this object.
Note: do not delete the pointer returned by this function or pass it to another function that could delete it, including creating QSharedPointer or QWeakPointer objects.
Definition at line 284 of file qsharedpointer_impl.h.
Referenced by QSharedPointer< QWindowsFontEngineData >::comparesEqual, QSharedPointer< QWindowsFontEngineData >::isNull(), QSharedPointer< QWindowsFontEngineData >::operator*(), and QSharedPointer< QWindowsFontEngineData >::operator->().
|
inline |
Definition at line 400 of file qsharedpointer_impl.h.
|
inline |
Definition at line 394 of file qsharedpointer_impl.h.
|
inlinenoexcept |
Same as data().
This function is provided for API compatibility with {std::shared_ptr}.
Definition at line 285 of file qsharedpointer_impl.h.
|
inlinenoexcept |
Returns true if this object refers to \nullptr.
Definition at line 286 of file qsharedpointer_impl.h.
Referenced by QSharedPointer< QWindowsFontEngineData >::operator bool(), and QSharedPointer< QWindowsFontEngineData >::operator!().
|
inline |
Definition at line 425 of file qsharedpointer_impl.h.
|
inline |
Definition at line 419 of file qsharedpointer_impl.h.
|
inlineexplicitnoexcept |
Returns true if the contained pointer is not \nullptr.
This function is suitable for use in \tt if-constructs, like:
Definition at line 287 of file qsharedpointer_impl.h.
|
inlinenoexcept |
Returns true if this object refers to \nullptr.
This function is suitable for use in \tt if-constructs, like:
Definition at line 288 of file qsharedpointer_impl.h.
|
inline |
Provides access to the shared pointer's members.
If the contained pointer is \nullptr, behavior is undefined.
Definition at line 289 of file qsharedpointer_impl.h.
|
inlinenoexcept |
Provides access to the shared pointer's members.
If the contained pointer is \nullptr, behavior is undefined.
Definition at line 290 of file qsharedpointer_impl.h.
|
inlinenoexcept |
Makes this object share other's pointer.
The current pointer reference is discarded and, if it was the last, the pointer will be deleted.
If \tt T is a derived type of the template parameter of this class, QSharedPointer will perform an automatic cast. Otherwise, you will get a compiler error.
Definition at line 317 of file qsharedpointer_impl.h.
|
inline |
Definition at line 355 of file qsharedpointer_impl.h.
|
inline |
Definition at line 368 of file qsharedpointer_impl.h.
|
inlinenoexcept |
Move-assigns other to this QSharedPointer instance.
\constraints {X*} implicitly converts to {T*}.
Definition at line 342 of file qsharedpointer_impl.h.
|
inlinenoexcept |
Definition at line 462 of file qsharedpointer_impl.h.
|
inlinenoexcept |
Definition at line 465 of file qsharedpointer_impl.h.
|
inlinenoexcept |
Definition at line 469 of file qsharedpointer_impl.h.
|
inlinenoexcept |
Definition at line 472 of file qsharedpointer_impl.h.
|
inlinenoexcept |
Definition at line 475 of file qsharedpointer_impl.h.
|
inline |
Same as clear(). For std::shared_ptr compatibility.
Definition at line 374 of file qsharedpointer_impl.h.
|
inline |
Resets this QSharedPointer object to point to t instead. Equivalent to:
Definition at line 375 of file qsharedpointer_impl.h.
|
inline |
Resets this QSharedPointer object to point to t instead, with the Deleter deleter. Equivalent to:
Definition at line 378 of file qsharedpointer_impl.h.
|
inline |
Definition at line 388 of file qsharedpointer_impl.h.
|
inline |
Definition at line 382 of file qsharedpointer_impl.h.
|
inlinenoexcept |
Definition at line 371 of file qsharedpointer_impl.h.
|
nodiscard |
Returns a weak reference object that shares the pointer referenced by this object.
Definition at line 872 of file qsharedpointer_impl.h.
Creates a QSharedPointer that is null (the object is holding a reference to \nullptr).
Definition at line 553 of file qsharedpointer_impl.h.
|
friend |
Definition at line 480 of file qsharedpointer_impl.h.
|
friend |
Definition at line 500 of file qsharedpointer_impl.h.
|
friend |
Definition at line 484 of file qsharedpointer_impl.h.
|
friend |
Definition at line 503 of file qsharedpointer_impl.h.
|
friend |
Definition at line 496 of file qsharedpointer_impl.h.
|
Returns true if lhs and rhs refer to distinct pointers.
\fn template<class T, class X> bool operator==(const QSharedPointer<T> &lhs, const QSharedPointer<X> &rhs) \relates QSharedPointer Returns \c true if \a lhs and \a rhs refer to the same pointer.
! [qsharedpointer-different-template-parameters] If rhs's template parameter is different from lhs's, QSharedPointer first needs to ensure that they are compatible types. It will attempt to perform an automatic \tt static_cast to convert the types \tt T and \tt X to their composite pointer type. If rhs's template parameter is not a base or a derived type from lhs's, you will get a compiler error. ! [qsharedpointer-different-template-parameters]
qsharedpointer-different-template-parameters
|
Returns true if lhs and rhs refer to distinct pointers.
qsharedpointer-different-template-parameters
|
Returns true if lhs refers to a valid (i.e. non-null) pointer.
|
Returns true if the pointer lhs is not the same pointer as that referenced by rhs.
qsharedpointer-different-template-parameters
|
Returns true if rhs refers to a valid (i.e. non-null) pointer.
|
|
Returns true if lhs and rhs refer to the same pointer.
qsharedpointer-different-template-parameters
|
|
Returns true if the pointer lhs is the same pointer as that referenced by rhs.
qsharedpointer-different-template-parameters
|
|
Returns a shared pointer to the pointer held by src.
Same as qSharedPointerObjectCast(). This function is provided for STL compatibility.
Definition at line 1032 of file qsharedpointer_impl.h.
|
Same as qSharedPointerObjectCast(). This function is provided for STL compatibility.
Definition at line 1041 of file qsharedpointer_impl.h.
|
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.
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.
|
{cast-overload-for-arg} {other}
|
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.
|
{cast-overload-for-arg} {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.
If the \tt dynamic_cast fails, the object returned will be null.
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.
|
{cast-overload-for-arg} {src}
|
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.
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.
|
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.
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 const_pointer_cast to cast away the constness.
Definition at line 1056 of file qsharedpointer_impl.h.
|
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 succeeds, the function will return a valid shared pointer, and src is reset to null. If the \tt qobject_cast fails, the object returned will be null, and src will not be modified.
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 const_pointer_cast to cast away the constness.
Definition at line 1062 of file qsharedpointer_impl.h.
|
{cast-overload-for-arg} {src}
|
friend |
|
friend |
Definition at line 554 of file qsharedpointer_impl.h.