views:

1903

answers:

1

Like it has been written here Qt up to now has 8 specilized smart pointer classes. It looks like it is all you will ever need. However, in order to use any of these smart pointers your class must be derived from QObject which is not always convenient. Is there other implementations of smart pointers in Qt which work with arbitrary classes?

+4  A: 

Virtually everything in Qt is derived from QObject, and while some of the built in smart pointer classes are related to QObject (or QSharedData), the QSharedPointer and QScopedPointer templates appear to allow pointers to anything.

Beyond that, you'll find some smart pointer templates in Boost:

  • scoped_ptr - Simple sole ownership of single objects. Noncopyable.
  • scoped_array - Simple sole ownership of arrays. Noncopyable.
  • shared_ptr - Object ownership shared among multiple pointers.
  • shared_array - Array ownership shared among multiple pointers.
  • weak_ptr - Non-owning observers of an object owned by shared_ptr.
  • intrusive_ptr - Shared ownership of objects with an embedded reference count.
Paul Dixon
This is right. STL also has auto_ptr. The question is about QT.
AlexKR
Virtually everything in Qt using QObject as a base, so if you want something that works outside of that, Boost one place to go looking :)
Paul Dixon
Wow, i still use C++ like "C with classes" (thats C++ around 1990). That works, all this ugly unreadable smart pointers insaneness make me sick.
Lothar
Yeah, automatic memory management, eew, disgusting. How can we trust a C++ application if it doesn't have memory leaks? ;)
jalf