A new autoptr class for QPointer.

Review Request #955 - Created July 8, 2009 and updated

Information
David Jarvie
kde
Reviewers
kdelibs
This template class is inherited from QPointer, and provides the additional feature that on destruction it deletes the QObject whose pointer it contains.

The motivation for adding this class is to deal with the issue described in  http://www.kdedevelopers.org/node/3919, whereby if a modal dialog is open when an application is told to quit, the dialog will be deleted by its parent, usually resulting in a crash due to double deletion of the dialog, or due to accessing the dangling pointer to the dialog.

This class is required by several applications in kdepim, and other modules would also benefit by using it.

A unit test will be provided if the class is approved.
Works successfully in KAlarm.
Thomas McGuire
Seems fine to me, this would be something really useful, especially because we have to wait for QScopedPointer until at least 4.6.

So I think this should be included in kdelibs.
Ingo Klöcker
I advise against deriving KAutoPointer from QPointer because QPointer is not virtual. I suggest using composition (i.e. an internal QPointer) instead of derivation.
Alex Merry
Do we still want this?  We now have QScopedPointer, but it doesn't do quite what this does (it doesn't watch for QObjects being deleted).
  1. Imo this should not go into kdelibs, as QPointer is notoriously slow and it's advised to use QWeakPointer instead. The patch as-is seems more appropriate for legacy systems.
Loading...