class KSharedPtr< T >
Can be used to control the lifetime of an object that has derived QSharedData.
As long a someone holds a KSharedPtr on some QSharedData object it won't become deleted but is deleted once its reference count is 0. This struct emulates C++ pointers virtually perfectly. So just use it like a simple C++ pointer.
The difference with QSharedPointer is that QSharedPointer does the refcounting in the pointer, while KSharedPtr does the refcounting in the object. This allows to convert to a raw pointer temporarily and back to a KSharedPtr without deleting the object, if another reference exists. But it imposes a requirement on the object, which must inherit QSharedData.
The difference with using QSharedDataPointer is that QSharedDataPointer is a building block for implementing a value class with implicit sharing (like QString), whereas KSharedPtr provides refcounting to code that uses pointers.
- Waldo Bastian basti[email protected][email protected][email protected]de.or[email protected]g
- use QExplicitlySharedDataPointer instead
Definition at line 66 of file ksharedptr.h.
template<class U >
Convert KSharedPtr<U> to KSharedPtr<T>, using a dynamic_cast.
This will compile whenever T* and U* are compatible, i.e. T is a subclass of U or vice-versa. Example syntax:
KSharedPtr<T> tPtr; KSharedPtr<U> uPtr = KSharedPtr<U>::dynamicCast( tPtr ); Since a dynamic_cast is used, if U derives from T, and tPtr isn't an instance of U, uPtr will be 0.
Definition at line 269 of file ksharedptr.h.