Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QSharedPointer< T > Class Template Reference

\inmodule QtCore More...

#include <qsharedpointer_impl.h>

+ Collaboration diagram for QSharedPointer< T >:

Public Types

typedef T Type
 
typedef T element_type
 
typedef T value_type
 
typedef value_typepointer
 
typedef const value_typeconst_pointer
 
typedef value_typereference
 
typedef const value_typeconst_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.
 
QSharedPointeroperator= (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>
QSharedPointeroperator= (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>
QSharedPointeroperator= (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< XstaticCast () const &
 
template<class X>
QSharedPointer< XstaticCast () &&
 
template<class X>
QSharedPointer< XdynamicCast () const &
 
template<class X>
QSharedPointer< XdynamicCast () &&
 
template<class X>
QSharedPointer< XconstCast () const &
 
template<class X>
QSharedPointer< XconstCast () &&
 
template<class X>
QSharedPointer< XobjectCast () const &
 
template<class X>
QSharedPointer< XobjectCast () &&
 
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< XQtSharedPointer::copyAndSetPointer (X *ptr, const QSharedPointer< Y > &src)
 
template<class X, class Y>
QSharedPointer< XQtSharedPointer::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< XqSharedPointerCast (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< XqSharedPointerCastqSharedPointerCast (QSharedPointer< T > &&other)(const QSharedPointer< T > &other)
 
template< class X, class T > QSharedPointer< XqSharedPointerDynamicCast (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< XqSharedPointerDynamicCastqSharedPointerDynamicCast (QSharedPointer< T > &&src)(const QSharedPointer< T > &src)
 
template< class X, class T > QSharedPointer< XqSharedPointerConstCast (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< XqSharedPointerConstCastqSharedPointerConstCast (QSharedPointer< T > &&src)(const QSharedPointer< T > &src)
 
template< class X, class T > QSharedPointer< XqSharedPointerObjectCast (const QSharedPointer< T > &src)
 The qSharedPointerObjectCast function is for casting a shared pointer.
 
template< class X, class T > QSharedPointer< XqSharedPointerObjectCastqSharedPointerObjectCast (QSharedPointer< T > &&src)(const QSharedPointer< T > &src)
 
template< class X, class T > std::shared_ptr< XqSharedPointerObjectCast (const std::shared_ptr< T > &src)
 
template< class X, class T > std::shared_ptr< Xqobject_pointer_cast (const std::shared_ptr< T > &src)
 
template< class X, class T > std::shared_ptr< XqSharedPointerObjectCast (std::shared_ptr< T > &&src)
 
template< class X, class T > std::shared_ptr< Xqobject_pointer_cast (std::shared_ptr< T > &&src)
 

Detailed Description

template<class T>
class QSharedPointer< T >

\inmodule QtCore

The QSharedPointer class holds a strong reference to a shared pointer.

Since
4.5

\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++. 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 267 of file qsharedpointer_impl.h.

Member Typedef Documentation

◆ const_pointer

template<class T>
typedef const value_type* QSharedPointer< T >::const_pointer

Definition at line 278 of file qsharedpointer_impl.h.

◆ const_reference

template<class T>
typedef const value_type& QSharedPointer< T >::const_reference

Definition at line 280 of file qsharedpointer_impl.h.

◆ difference_type

template<class T>
typedef qptrdiff QSharedPointer< T >::difference_type

Definition at line 281 of file qsharedpointer_impl.h.

◆ element_type

template<class T>
typedef T QSharedPointer< T >::element_type

Definition at line 275 of file qsharedpointer_impl.h.

◆ pointer

template<class T>
typedef value_type* QSharedPointer< T >::pointer

Definition at line 277 of file qsharedpointer_impl.h.

◆ reference

template<class T>
typedef value_type& QSharedPointer< T >::reference

Definition at line 279 of file qsharedpointer_impl.h.

◆ Type

template<class T>
typedef T QSharedPointer< T >::Type

Definition at line 274 of file qsharedpointer_impl.h.

◆ value_type

template<class T>
typedef T QSharedPointer< T >::value_type

Definition at line 276 of file qsharedpointer_impl.h.

Constructor & Destructor Documentation

◆ QSharedPointer() [1/10]

template<class T>
Q_NODISCARD_CTOR constexpr QSharedPointer< T >::QSharedPointer ( )
inlineconstexprnoexcept

Definition at line 292 of file qsharedpointer_impl.h.

◆ ~QSharedPointer()

template<class T>
QSharedPointer< T >::~QSharedPointer ( )
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 293 of file qsharedpointer_impl.h.

◆ QSharedPointer() [2/10]

template<class T>
Q_NODISCARD_CTOR constexpr QSharedPointer< T >::QSharedPointer ( std::nullptr_t )
inlineconstexprnoexcept
Since
5.8

Creates a QSharedPointer that is null. This is equivalent to the QSharedPointer default constructor.

Definition at line 296 of file qsharedpointer_impl.h.

◆ QSharedPointer() [3/10]

template<class T>
template<class X, IfCompatible< X > = true>
Q_NODISCARD_CTOR QSharedPointer< T >::QSharedPointer ( X * ptr)
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 300 of file qsharedpointer_impl.h.

◆ QSharedPointer() [4/10]

template<class T>
template<class X, typename Deleter, IfCompatible< X > = true>
Q_NODISCARD_CTOR QSharedPointer< T >::QSharedPointer ( X * ptr,
Deleter d )
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:

static void doDeleteLater(MyObject *obj)
{
obj->deleteLater();
}
{
// continue using obj
obj.clear(); // calls obj->deleteLater();
}

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:

See also
clear()

Definition at line 305 of file qsharedpointer_impl.h.

◆ QSharedPointer() [5/10]

template<class T>
template<typename Deleter>
Q_NODISCARD_CTOR QSharedPointer< T >::QSharedPointer ( std::nullptr_t ,
Deleter d )
inline
Since
5.8

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 310 of file qsharedpointer_impl.h.

◆ QSharedPointer() [6/10]

template<class T>
Q_NODISCARD_CTOR QSharedPointer< T >::QSharedPointer ( const QSharedPointer< T > & other)
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 314 of file qsharedpointer_impl.h.

◆ QSharedPointer() [7/10]

template<class T>
Q_NODISCARD_CTOR QSharedPointer< T >::QSharedPointer ( QSharedPointer< T > && other)
inlinenoexcept

Move-constructs a QSharedPointer instance, making it point at the same object that other was pointing to.

Since
5.4

Definition at line 323 of file qsharedpointer_impl.h.

◆ QSharedPointer() [8/10]

template<class T>
template<class X, IfCompatible< X > = true>
Q_NODISCARD_CTOR QSharedPointer< T >::QSharedPointer ( QSharedPointer< X > && other)
inlinenoexcept

Move-constructs a QSharedPointer instance, making it point at the same object that other was pointing to.

\constraints {X*} implicitly converts to {T*}.

Since
5.6

Definition at line 333 of file qsharedpointer_impl.h.

◆ QSharedPointer() [9/10]

template<class T>
template<class X, IfCompatible< X > = true>
Q_NODISCARD_CTOR QSharedPointer< T >::QSharedPointer ( const QSharedPointer< X > & other)
inlinenoexcept

Definition at line 350 of file qsharedpointer_impl.h.

◆ QSharedPointer() [10/10]

template<class T>
template<class X, IfCompatible< X > = true>
Q_NODISCARD_CTOR QSharedPointer< T >::QSharedPointer ( const QWeakPointer< X > & other)
inline

Definition at line 363 of file qsharedpointer_impl.h.

Member Function Documentation

◆ clear()

template<class T>
void QSharedPointer< T >::clear ( )
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 430 of file qsharedpointer_impl.h.

◆ constCast() [1/2]

template<class T>
template<class X>
QSharedPointer< X > QSharedPointer< T >::constCast ( ) &&
inline

Definition at line 411 of file qsharedpointer_impl.h.

◆ constCast() [2/2]

template<class T>
template<class X>
QSharedPointer< X > QSharedPointer< T >::constCast ( ) const &
inline

Definition at line 405 of file qsharedpointer_impl.h.

◆ create()

template<class T>
template<typename... Args>
static QSharedPointer QSharedPointer< T >::create ( Args &&... args)
inlinestaticnodiscard

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
5.1

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 435 of file qsharedpointer_impl.h.

◆ data()

template<class T>
T * QSharedPointer< T >::data ( ) const
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 283 of file qsharedpointer_impl.h.

Referenced by QSharedPointer< QWindowsFontEngineData >::comparesEqual, QSharedPointer< QWindowsFontEngineData >::isNull(), QSharedPointer< QWindowsFontEngineData >::operator*(), and QSharedPointer< QWindowsFontEngineData >::operator->().

+ Here is the caller graph for this function:

◆ dynamicCast() [1/2]

template<class T>
template<class X>
QSharedPointer< X > QSharedPointer< T >::dynamicCast ( ) &&
inline

Definition at line 399 of file qsharedpointer_impl.h.

◆ dynamicCast() [2/2]

template<class T>
template<class X>
QSharedPointer< X > QSharedPointer< T >::dynamicCast ( ) const &
inline

Definition at line 393 of file qsharedpointer_impl.h.

◆ get()

template<class T>
T * QSharedPointer< T >::get ( ) const
inlinenoexcept
Since
5.11

Same as data().

This function is provided for API compatibility with {std::shared_ptr}.

Definition at line 284 of file qsharedpointer_impl.h.

◆ isNull()

template<class T>
bool QSharedPointer< T >::isNull ( ) const
inlinenoexcept

Returns true if this object refers to \nullptr.

Definition at line 285 of file qsharedpointer_impl.h.

Referenced by QSharedPointer< QWindowsFontEngineData >::operator bool(), and QSharedPointer< QWindowsFontEngineData >::operator!().

+ Here is the caller graph for this function:

◆ objectCast() [1/2]

template<class T>
template<class X>
QSharedPointer< X > QSharedPointer< T >::objectCast ( ) &&
inline

Definition at line 424 of file qsharedpointer_impl.h.

◆ objectCast() [2/2]

template<class T>
template<class X>
QSharedPointer< X > QSharedPointer< T >::objectCast ( ) const &
inline

Definition at line 418 of file qsharedpointer_impl.h.

◆ operator bool()

template<class T>
QSharedPointer< T >::operator bool ( ) const
inlineexplicitnoexcept

Returns true if the contained pointer is not \nullptr.

This function is suitable for use in \tt if-constructs, like:

if (sharedptr) { ... }
See also
isNull()

Definition at line 286 of file qsharedpointer_impl.h.

◆ operator!()

template<class T>
bool QSharedPointer< T >::operator! ( ) const
inlinenoexcept

Returns true if this object refers to \nullptr.

This function is suitable for use in \tt if-constructs, like:

if (!sharedptr) { ... }
See also
isNull()

Definition at line 287 of file qsharedpointer_impl.h.

◆ operator*()

template<class T>
T & QSharedPointer< T >::operator* ( ) const
inline

Provides access to the shared pointer's members.

If the contained pointer is \nullptr, behavior is undefined.

See also
isNull()

Definition at line 288 of file qsharedpointer_impl.h.

◆ operator->()

template<class T>
T * QSharedPointer< T >::operator-> ( ) const
inlinenoexcept

Provides access to the shared pointer's members.

If the contained pointer is \nullptr, behavior is undefined.

See also
isNull()

Definition at line 289 of file qsharedpointer_impl.h.

◆ operator=() [1/4]

template<class T>
QSharedPointer & QSharedPointer< T >::operator= ( const QSharedPointer< T > & other)
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 316 of file qsharedpointer_impl.h.

◆ operator=() [2/4]

template<class T>
template<class X, IfCompatible< X > = true>
QSharedPointer & QSharedPointer< T >::operator= ( const QSharedPointer< X > & other)
inline

Definition at line 354 of file qsharedpointer_impl.h.

◆ operator=() [3/4]

template<class T>
template<class X, IfCompatible< X > = true>
QSharedPointer< T > & QSharedPointer< T >::operator= ( const QWeakPointer< X > & other)
inline

Definition at line 367 of file qsharedpointer_impl.h.

◆ operator=() [4/4]

template<class T>
template<class X, IfCompatible< X > = true>
QSharedPointer & QSharedPointer< T >::operator= ( QSharedPointer< X > && other)
inlinenoexcept

Move-assigns other to this QSharedPointer instance.

\constraints {X*} implicitly converts to {T*}.

Since
5.6

Definition at line 341 of file qsharedpointer_impl.h.

◆ owner_before() [1/2]

template<class T>
template<typename X>
bool QSharedPointer< T >::owner_before ( const QSharedPointer< X > & other) const
inlinenoexcept

Definition at line 461 of file qsharedpointer_impl.h.

◆ owner_before() [2/2]

template<class T>
template<typename X>
bool QSharedPointer< T >::owner_before ( const QWeakPointer< X > & other) const
inlinenoexcept

Definition at line 464 of file qsharedpointer_impl.h.

◆ owner_equal() [1/2]

template<class T>
template<typename X>
bool QSharedPointer< T >::owner_equal ( const QSharedPointer< X > & other) const
inlinenoexcept

Definition at line 468 of file qsharedpointer_impl.h.

◆ owner_equal() [2/2]

template<class T>
template<typename X>
bool QSharedPointer< T >::owner_equal ( const QWeakPointer< X > & other) const
inlinenoexcept

Definition at line 471 of file qsharedpointer_impl.h.

◆ owner_hash()

template<class T>
size_t QSharedPointer< T >::owner_hash ( ) const
inlinenoexcept

Definition at line 474 of file qsharedpointer_impl.h.

◆ reset() [1/3]

template<class T>
void QSharedPointer< T >::reset ( )
inline
Since
5.0

Same as clear(). For std::shared_ptr compatibility.

Definition at line 373 of file qsharedpointer_impl.h.

◆ reset() [2/3]

template<class T>
void QSharedPointer< T >::reset ( T * t)
inline
Since
5.0

Resets this QSharedPointer object to point to t instead. Equivalent to:

Definition at line 374 of file qsharedpointer_impl.h.

◆ reset() [3/3]

template<class T>
template<typename Deleter>
void QSharedPointer< T >::reset ( T * t,
Deleter deleter )
inline
Since
5.0

Resets this QSharedPointer object to point to t instead, with the Deleter deleter. Equivalent to:

QSharedPointer<T> other(t, deleter); this->swap(other);

Definition at line 377 of file qsharedpointer_impl.h.

◆ staticCast() [1/2]

template<class T>
template<class X>
QSharedPointer< X > QSharedPointer< T >::staticCast ( ) &&
inline

Definition at line 387 of file qsharedpointer_impl.h.

◆ staticCast() [2/2]

template<class T>
template<class X>
QSharedPointer< X > QSharedPointer< T >::staticCast ( ) const &
inline

Definition at line 381 of file qsharedpointer_impl.h.

◆ swap()

template<class T>
void QSharedPointer< T >::swap ( QSharedPointer< T > & other)
inlinenoexcept
Since
5.3 \memberswap{shared pointer instance}

Definition at line 370 of file qsharedpointer_impl.h.

◆ toWeakRef()

template<class T>
Q_INLINE_TEMPLATE QWeakPointer< T > QSharedPointer< T >::toWeakRef ( ) const
nodiscard

Returns a weak reference object that shares the pointer referenced by this object.

See also
QWeakPointer::QWeakPointer()

Definition at line 863 of file qsharedpointer_impl.h.

Friends And Related Symbol Documentation

◆ QSharedPointer

template<class T>
template<class X>
friend class QSharedPointer
friend

Creates a QSharedPointer that is null (the object is holding a reference to \nullptr).

Definition at line 552 of file qsharedpointer_impl.h.

◆ comparesEqual [1/2]

template<class T>
template<typename X>
bool comparesEqual ( const QSharedPointer< T > & lhs,
const QSharedPointer< X > & rhs )
friend

Definition at line 479 of file qsharedpointer_impl.h.

◆ comparesEqual [2/2]

template<class T>
bool comparesEqual ( const QSharedPointer< T > & lhs,
std::nullptr_t  )
friend

Definition at line 499 of file qsharedpointer_impl.h.

◆ compareThreeWay [1/3]

template<class T>
template<typename X>
Qt::strong_ordering compareThreeWay ( const QSharedPointer< T > & lhs,
const QSharedPointer< X > & rhs )
friend

Definition at line 483 of file qsharedpointer_impl.h.

◆ compareThreeWay [2/3]

template<class T>
Qt::strong_ordering compareThreeWay ( const QSharedPointer< T > & lhs,
std::nullptr_t  )
friend

Definition at line 502 of file qsharedpointer_impl.h.

◆ compareThreeWay [3/3]

template<class T>
template<typename X>
Qt::strong_ordering compareThreeWay ( const QSharedPointer< T > & lhs,
X * rhs )
friend

Definition at line 495 of file qsharedpointer_impl.h.

◆ operator!=() [1/5]

template<class T>
template< class T, class X > bool operator!= ( const QSharedPointer< T > & lhs,
const QSharedPointer< X > & rhs )
related

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

◆ operator!=() [2/5]

template<class T>
template< class T, class X > bool operator!= ( const QSharedPointer< T > & lhs,
const X * rhs )
related

Returns true if lhs and rhs refer to distinct pointers.

qsharedpointer-different-template-parameters

◆ operator!=() [3/5]

template<class T>
template< class T > bool operator!= ( const QSharedPointer< T > & lhs,
std::nullptr_t  )
related
Since
5.8

Returns true if lhs refers to a valid (i.e. non-null) pointer.

See also
QSharedPointer::isNull()

◆ operator!=() [4/5]

template<class T>
template< class T, class X > bool operator!= ( const T * lhs,
const QSharedPointer< X > & rhs )
related

Returns true if the pointer lhs is not the same pointer as that referenced by rhs.

qsharedpointer-different-template-parameters

◆ operator!=() [5/5]

template<class T>
template< class T > bool operator!= ( std::nullptr_t ,
const QSharedPointer< T > & rhs )
related
Since
5.8

Returns true if rhs refers to a valid (i.e. non-null) pointer.

See also
QSharedPointer::isNull()

◆ operator<<()

template<class T>
template< typename T > QDebug operator<< ( QDebug debug,
const QSharedPointer< T > & ptr )
related
Since
5.7

Writes the pointer tracked by ptr into the debug object debug for debugging purposes.

See also
{Debugging Techniques}

Definition at line 592 of file qdebug.h.

◆ operator==() [1/4]

template<class T>
template< class T, class X > bool operator== ( const QSharedPointer< T > & lhs,
const X * rhs )
related

Returns true if lhs and rhs refer to the same pointer.

qsharedpointer-different-template-parameters

◆ operator==() [2/4]

template<class T>
template< class T > bool operator== ( const QSharedPointer< T > & lhs,
std::nullptr_t  )
related
Since
5.8

Returns true if lhs refers to \nullptr.

See also
QSharedPointer::isNull()

◆ operator==() [3/4]

template<class T>
template< class T, class X > bool operator== ( const T * lhs,
const QSharedPointer< X > & rhs )
related

Returns true if the pointer lhs is the same pointer as that referenced by rhs.

qsharedpointer-different-template-parameters

◆ operator==() [4/4]

template<class T>
template< class T > bool operator== ( std::nullptr_t ,
const QSharedPointer< T > & rhs )
related
Since
5.8

Returns true if rhs refers to \nullptr.

See also
QSharedPointer::isNull()

◆ qobject_pointer_cast() [1/2]

template<class T>
template< class X, class T > std::shared_ptr< X > qobject_pointer_cast ( const std::shared_ptr< T > & src)
related
Since
5.14

Returns a shared pointer to the pointer held by src.

Same as qSharedPointerObjectCast(). This function is provided for STL compatibility.

Definition at line 1023 of file qsharedpointer_impl.h.

◆ qobject_pointer_cast() [2/2]

template<class T>
template< class X, class T > std::shared_ptr< X > qobject_pointer_cast ( std::shared_ptr< T > && src)
related
Since
5.14

Same as qSharedPointerObjectCast(). This function is provided for STL compatibility.

Definition at line 1032 of file qsharedpointer_impl.h.

◆ qSharedPointerCast()

template<class T>
template< class X, class T > QSharedPointer< X > qSharedPointerCast ( const QSharedPointer< T > & other)
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.

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.

See also
QSharedPointer::staticCast(), qSharedPointerDynamicCast(), qSharedPointerConstCast()

◆ qSharedPointerCastqSharedPointerCast()

template<class T>
template< class X, class T > QSharedPointer< X > qSharedPointerCastqSharedPointerCast ( QSharedPointer< T > && other) const &
related
Since
6.9

{cast-overload-for-arg} {other}

See also
QSharedPointer::staticCast(), qSharedPointerDynamicCast(), qSharedPointerConstCast()

◆ qSharedPointerConstCast()

template<class T>
template< class X, class T > QSharedPointer< X > qSharedPointerConstCast ( const QSharedPointer< T > & src)
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.

See also
QSharedPointer::constCast(), qSharedPointerCast(), qSharedPointerDynamicCast()

◆ qSharedPointerConstCastqSharedPointerConstCast()

template<class T>
template< class X, class T > QSharedPointer< X > qSharedPointerConstCastqSharedPointerConstCast ( QSharedPointer< T > && src) const &
related
Since
6.9

{cast-overload-for-arg} {src}

See also
QSharedPointer::constCast(), qSharedPointerCast(), qSharedPointerDynamicCast()

◆ qSharedPointerDynamicCast()

template<class T>
template< class X, class T > QSharedPointer< X > qSharedPointerDynamicCast ( const QSharedPointer< T > & src)
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.

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.

See also
QSharedPointer::dynamicCast(), qSharedPointerCast(), qSharedPointerConstCast()

◆ qSharedPointerDynamicCastqSharedPointerDynamicCast()

template<class T>
template< class X, class T > QSharedPointer< X > qSharedPointerDynamicCastqSharedPointerDynamicCast ( QSharedPointer< T > && src) const &
related
Since
6.9

{cast-overload-for-arg} {src}

See also
QSharedPointer::dynamicCast(), qSharedPointerCast(), qSharedPointerConstCast()

◆ qSharedPointerObjectCast() [1/3]

template<class T>
template< class X, class T > QSharedPointer< X > qSharedPointerObjectCast ( const QSharedPointer< T > & src)
related

The qSharedPointerObjectCast function is for casting a shared pointer.

Since
4.6

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.

See also
QSharedPointer::objectCast(), qSharedPointerCast(), qSharedPointerConstCast()

◆ qSharedPointerObjectCast() [2/3]

template<class T>
template< class X, class T > std::shared_ptr< X > qSharedPointerObjectCast ( const std::shared_ptr< T > & src)
related
Since
5.14

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 1047 of file qsharedpointer_impl.h.

◆ qSharedPointerObjectCast() [3/3]

template<class T>
template< class X, class T > std::shared_ptr< X > qSharedPointerObjectCast ( std::shared_ptr< T > && src)
related
Since
5.14

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 1053 of file qsharedpointer_impl.h.

◆ qSharedPointerObjectCastqSharedPointerObjectCast()

template<class T>
template< class X, class T > QSharedPointer< X > qSharedPointerObjectCastqSharedPointerObjectCast ( QSharedPointer< T > && src) const &
related
Since
6.9

{cast-overload-for-arg} {src}

See also
QSharedPointer::objectCast(), qSharedPointerCast(), qSharedPointerConstCast()

◆ QtSharedPointer::copyAndSetPointer

template<class T>
template<class X, class Y>
QSharedPointer< X > QtSharedPointer::copyAndSetPointer ( X * ptr,
const QSharedPointer< Y > & src )
friend

◆ QtSharedPointer::movePointer

template<class T>
template<class X, class Y>
QSharedPointer< X > QtSharedPointer::movePointer ( X * ptr,
QSharedPointer< Y > && src )
friend

◆ QWeakPointer


The documentation for this class was generated from the following files: