QGIS API Documentation 3.43.0-Master (3ee7834ace6)
Public Member Functions | List of all members
QObjectParentUniquePtr< T > Class Template Reference

Keeps a pointer to an object owned by a QObject parent, and deletes it whenever this parent object is deleted. More...

#include <qobjectuniqueptr.h>

Public Member Functions

 QObjectParentUniquePtr ()
 Creates a new empty QObjectParentUniquePtr.
 
 QObjectParentUniquePtr (T *child, QObject *parent)
 Takes a new QObjectParentUniquePtr and assign a child to it.
 
 ~QObjectParentUniquePtr ()
 Will delete the contained object if the parent still exists.
 
void clear ()
 Clears the pointer.
 
T * data () const
 Returns the raw pointer to the managed QObject.
 
T * get () const
 Returns the raw pointer to the managed child.
 
bool isNull () const
 Checks if the managed pointer is nullptr.
 
 operator bool () const
 Checks if the pointer managed by this object is nullptr.
 
 operator T* () const
 Const getter for the managed raw pointer.
 
T & operator* () const
 Dereferences the managed child.
 
T * operator-> () const
 Returns a raw pointer to the managed child.
 
QObjectParentUniquePtr< T > & operator= (T *child)
 Assigns a new child to the pointer.
 
T * release ()
 Clears the pointer and returns it.
 
void reset (T *p=nullptr)
 Will reset the managed pointer to p.
 
void setParentOwner (QObject *parent)
 Sets the parent object.
 

Detailed Description

template<class T>
class QObjectParentUniquePtr< T >

Keeps a pointer to an object owned by a QObject parent, and deletes it whenever this parent object is deleted.

It keeps a weak pointer to the QObject parent internally and the object pointer be set to nullptr whenever the parent QObject is deleted.

See also
QObjectUniquePtr for storage of QObject derived objects directly.
Since
QGIS 3.26

Definition at line 270 of file qobjectuniqueptr.h.

Constructor & Destructor Documentation

◆ QObjectParentUniquePtr() [1/2]

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

Creates a new empty QObjectParentUniquePtr.

Definition at line 284 of file qobjectuniqueptr.h.

◆ QObjectParentUniquePtr() [2/2]

template<class T >
QObjectParentUniquePtr< T >::QObjectParentUniquePtr ( T *  child,
QObject *  parent 
)
inline

Takes a new QObjectParentUniquePtr and assign a child to it.

Definition at line 290 of file qobjectuniqueptr.h.

◆ ~QObjectParentUniquePtr()

template<class T >
QObjectParentUniquePtr< T >::~QObjectParentUniquePtr ( )
inline

Will delete the contained object if the parent still exists.

Definition at line 303 of file qobjectuniqueptr.h.

Member Function Documentation

◆ clear()

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

Clears the pointer.

The managed object is set to nullptr and will not be deleted.

Definition at line 416 of file qobjectuniqueptr.h.

◆ data()

template<class T >
T * QObjectParentUniquePtr< T >::data ( ) const
inline

Returns the raw pointer to the managed QObject.

Definition at line 355 of file qobjectuniqueptr.h.

◆ get()

template<class T >
T * QObjectParentUniquePtr< T >::get ( ) const
inline

Returns the raw pointer to the managed child.

Definition at line 363 of file qobjectuniqueptr.h.

◆ isNull()

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

Checks if the managed pointer is nullptr.

Definition at line 397 of file qobjectuniqueptr.h.

◆ operator bool()

template<class T >
QObjectParentUniquePtr< T >::operator bool ( ) const
inlineexplicit

Checks if the pointer managed by this object is nullptr.

If it is not nullptr true will be returned, if it is NULLPTR false will be returned.

Definition at line 408 of file qobjectuniqueptr.h.

◆ operator T*()

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

Const getter for the managed raw pointer.

Definition at line 389 of file qobjectuniqueptr.h.

◆ operator*()

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

Dereferences the managed child.

Warning
Will deference a nullptr if the parent has been deleted.

Definition at line 381 of file qobjectuniqueptr.h.

◆ operator->()

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

Returns a raw pointer to the managed child.

Definition at line 371 of file qobjectuniqueptr.h.

◆ operator=()

template<class T >
QObjectParentUniquePtr< T > & QObjectParentUniquePtr< T >::operator= ( T *  child)
inline

Assigns a new child to the pointer.

The existing child will be deleted.

Definition at line 341 of file qobjectuniqueptr.h.

◆ release()

template<class T >
T * QObjectParentUniquePtr< T >::release ( )
inline

Clears the pointer and returns it.

The managed object will not be deleted and it is the callers responsibility to guarantee that no memory is leaked.

Definition at line 427 of file qobjectuniqueptr.h.

◆ reset()

template<class T >
void QObjectParentUniquePtr< T >::reset ( T *  p = nullptr)
inline

Will reset the managed pointer to p.

If there is already an object managed currently it will be deleted.

If p is not specified the managed object will be deleted and this object reset to nullptr.

Definition at line 442 of file qobjectuniqueptr.h.

◆ setParentOwner()

template<class T >
void QObjectParentUniquePtr< T >::setParentOwner ( QObject *  parent)
inline

Sets the parent object.

Definition at line 321 of file qobjectuniqueptr.h.


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