QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
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 269 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 283 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 289 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 302 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 415 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 354 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 362 of file qobjectuniqueptr.h.

◆ isNull()

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

Checks if the managed pointer is nullptr.

Definition at line 396 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 407 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 388 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 380 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 370 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 340 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 426 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 441 of file qobjectuniqueptr.h.

◆ setParentOwner()

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

Sets the parent object.

Definition at line 320 of file qobjectuniqueptr.h.


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