CopperSpice API  1.9.1
QPointer< T > Class Template Reference

Contains a pointer to a QObject. More...

Public Methods

 QPointer ()
 
 QPointer (const QPointer &other) = default
 
 QPointer (QPointer &&other) = default
 
 QPointer (T *ptr)
 
 ~QPointer () = default
 
void clear ()
 
T * data () const
 
bool isNull () const
 
 operator T * () const
 
T & operator* () const
 
T * operator-> () const
 
QPointer & operator= (const QPointer &other) = default
 
QPointer & operator= (QPointer &&other) = default
 
QPointer< T > & operator= (T *ptr)
 

Related Functions

These are not member functions

bool operator!= (const QPointer< T > &ptr1, const QPointer< T > &ptr2)
 
bool operator!= (const QPointer< T > &ptr1, const T *ptr2)
 
bool operator!= (const QPointer< T > &ptr1, T *ptr2)
 
bool operator!= (const T *ptr1, const QPointer< T > &ptr2)
 
bool operator!= (T *ptr1, const QPointer< T > &ptr2)
 
bool operator== (const QPointer< T > &ptr1, const QPointer< T > &ptr2)
 
bool operator== (const QPointer< T > &ptr1, const T *ptr2)
 
bool operator== (const QPointer< T > &ptr1, T *ptr2)
 
bool operator== (const T *ptr1, const QPointer< T > &a ptr2)
 
bool operator== (T *ptr1, const QPointer< T > &ptr2)
 

Detailed Description

template<class T>
class QPointer< T >

The QPointer class contains a pointer which can only point to a QObject or a child of QObject. The internal pointer is very similar to a weak pointer. However, there is no reference count in a QPointer, it is maintained in the QObject class. When a QObject or a class which inherits from QObject is deleted this class will contain a nullptr.

QPointer can never be used in a thread safe manner and should only be used in single threaded applications. From multi-threaded applications use a QSharedPointer with a QWeakPointer.

Example

label->setText("&Status:");
if (label != nullptr) {
label->show();
}

Constructor & Destructor Documentation

template<class T >
QPointer< T >::QPointer ( )
inline

Constructs QPointer which contains a null pointer.

template<class T >
QPointer< T >::QPointer ( T *  ptr)
inline

Constructs a QPointer which points to the same object which ptr points to. The template parameter T must inherit from QObject.

template<class T >
QPointer< T >::~QPointer ( )
default

Destroys the pointer.

template<class T >
QPointer< T >::QPointer ( const QPointer< T > &  other)
default

Copy constructs a new QPointer from other.

template<class T >
QPointer< T >::QPointer ( QPointer< T > &&  other)
default

Move constructs a new QPointer from other.

Method Documentation

template<class T >
void QPointer< T >::clear ( )
inline

Sets the current QPointer object to a null pointer.

See also
isNull()
template<class T >
T * QPointer< T >::data ( ) const
inline

Returns a raw pointer to the current object. The template parameter T must inherit from QObject.

template<class T >
bool QPointer< T >::isNull ( ) const
inline

Returns true if the referenced object has been destroyed or if there is no referenced object, otherwise returns false.

See also
clear()
template<class T >
QPointer< T >::operator T * ( ) const
inline

This method converts a QPointer to a raw pointer.

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

Dereferences this QPointer and returns the object it points to. If the QPointer is a nullptr the behavior is undefined.

template<class T >
T * QPointer< T >::operator-> ( ) const
inline

Dereferences this QPointer and returns a raw pointer to the object it points to. If the QPointer is a nullptr the behavior is undefined.

template<class T >
QPointer & QPointer< T >::operator= ( const QPointer< T > &  other)
default

Copy assigns from other and returns a reference to this object.

template<class T >
QPointer & QPointer< T >::operator= ( QPointer< T > &&  other)
default

Move assigns from other and returns a reference to this object.

template<class T >
QPointer< T > & QPointer< T >::operator= ( T *  ptr)
inline

Assigns ptr to this QPointer.

Friends And Related Function Documentation

bool operator!= ( const QPointer< T > &  ptr1,
const QPointer< T > &  ptr2 
)
related

Returns true if ptr1 and ptr2 do not point to the same object, otherwise returns false.

bool operator!= ( const QPointer< T > &  ptr1,
const T *  ptr2 
)
related

Returns true if ptr1 and ptr2 do not point to the same object, otherwise returns false.

bool operator!= ( const QPointer< T > &  ptr1,
T *  ptr2 
)
related

Returns true if ptr1 and ptr2 do not point to the same object, otherwise returns false.

bool operator!= ( const T *  ptr1,
const QPointer< T > &  ptr2 
)
related

Returns true if ptr1 and ptr2 do not point to the same object, otherwise returns false.

bool operator!= ( T *  ptr1,
const QPointer< T > &  ptr2 
)
related

Returns true if ptr1 and ptr2 do not point to the same object, otherwise returns false.

bool operator== ( const QPointer< T > &  ptr1,
const QPointer< T > &  ptr2 
)
related

Returns true if ptr1 and ptr2 point to the same object, otherwise returns false.

bool operator== ( const QPointer< T > &  ptr1,
const T *  ptr2 
)
related

Returns true if ptr1 and ptr2 point to the same object, otherwise returns false.

bool operator== ( const QPointer< T > &  ptr1,
T *  ptr2 
)
related

Returns true if ptr1 and ptr2 point to the same object, otherwise returns false.

bool operator== ( const T *  ptr1,
const QPointer< T > &a  ptr2 
)
related

Returns true if ptr1 and ptr2 point to the same object, otherwise returns false.

bool operator== ( T *  ptr1,
const QPointer< T > &  ptr2 
)
related

Returns true if ptr1 and ptr2 point to the same object, otherwise returns false.