Home · All Namespaces · All Classes · Main Classes · Grouped Classes · Modules · Functions

QWeakPointer Class Reference
[
QtCore module]

The QWeakPointer class holds a weak reference to a shared pointer More...

 #include <QWeakPointer>

Note: All the functions in this class are reentrant.

This class was introduced in Qt 4.5.

Public Functions


Detailed Description

The QWeakPointer class holds a weak reference to a shared pointer

The QWeakPointer is an automatic weak reference to a pointer in C++. It cannot be used to dereference the pointer directly, but it can be used to verify if the pointer has been deleted or not in another context.

QWeakPointer objects can only be created by assignment from a QSharedPointer.

To access the pointer that QWeakPointer is tracking, you must first create a QSharedPointer object and verify if the pointer is null or not.

See also QSharedPointer.


Member Function Documentation

QWeakPointer::QWeakPointer ()

Creates a QWeakPointer that points to nothing.

QWeakPointer::QWeakPointer ( const QWeakPointer<T> & other )

Creates a QWeakPointer that holds a weak reference to the pointer referenced by other.

If T is a derived type of the template parameter of this class, QWeakPointer will perform an automatic cast. Otherwise, you will get a compiler error.

Warning: Automatic downcasting is not available on MSVC 6. Use qWeakPointerCast() for portability to MSVC 6.

QWeakPointer::QWeakPointer ( const QSharedPointer<T> & other )

Creates a QWeakPointer that holds a weak reference to the pointer referenced by other.

If T is a derived type of the template parameter of this class, QWeakPointer will perform an automatic cast. Otherwise, you will get a compiler error.

Warning: Automatic downcasting is not available on MSVC 6. Use qWeakPointerCast() for portability to MSVC 6.

QWeakPointer::~QWeakPointer ()

Destroys this QWeakPointer object. The pointer referenced by this object will not be deleted.

bool QWeakPointer::isNull () const

Returns true if this object is holding a reference to a null pointer.

Note that, due to the nature of weak references, the pointer that QWeakPointer references can become null at any moment, so the value returned from this function can change from false to true from one call to the next.

QSharedPointer<T> QWeakPointer::toStrongPointer () const

QWeakPointer::operator bool () const

Returns true if this object is not null. This function is suitable for use in if-constructs, like:

 if (weakref) { ... }

Note that, due to the nature of weak references, the pointer that QWeakPointer references can become null at any moment, so the value returned from this function can change from true to false from one call to the next.

See also isNull().

bool QWeakPointer::operator! () const

Returns true if this object is null. This function is suitable for use in if-constructs, like:

 if (!weakref) { ... }

Note that, due to the nature of weak references, the pointer that QWeakPointer references can become null at any moment, so the value returned from this function can change from false to true from one call to the next.

See also isNull().

QWeakPointer<T> QWeakPointer::operator= ( const QWeakPointer<T> & other )

Makes this object share other's pointer. The current pointer reference is discarded but is not deleted.

If T is a derived type of the template parameter of this class, QWeakPointer will perform an automatic cast. Otherwise, you will get a compiler error.

Warning: Automatic downcasting is not available on MSVC 6. Use qWeakPointerCast() for portability to MSVC 6.

QWeakPointer<T> QWeakPointer::operator= ( const QSharedPointer<T> & other )

This is an overloaded member function, provided for convenience.

Makes this object share other's pointer. The current pointer reference is discarded but is not deleted.

If T is a derived type of the template parameter of this class, QWeakPointer will perform an automatic cast. Otherwise, you will get a compiler error.

Warning: Automatic downcasting is not available on MSVC 6. Use qWeakPointerCast() for portability to MSVC 6.


Copyright © 2008 Nokia Corporation and/or its subsidiary(-ies) Trademarks
Qt 4.5.0-tp1