Qt4 delete this vs deleteLater()

Thiago Macieira thiago at kde.org
Sun Aug 14 00:42:58 BST 2005


Dario Massarin wrote:
>So my question is: "What do you think about this?". Should we go through
>kdelibs and replace, in every QObject class, "delete this" with
> deleteLater() or there are cases in which this is not the right
> solution?

There are cases when deleteLater() may be unnecessary. So it is a 
case-by-case basis.

However, deleting an object from a slot is a BAD idea: you're deleting an 
object that is in use. I am saying that from the library developer point 
of view. Think of the following code:

	d->something = true
	emit finished();
	d->somethingElse = true;

If the slot connected to "finished" deleted the object, this code will 
either crash or cause memory corruption.

So, as a library developer, I try to avoid doing anything to the object 
after emitting any signals. But sometimes it isn't possible.

As for deleteLater(), don't think it'll magically solve all problems.

-- 
  Thiago Macieira  -  thiago (AT) macieira.info - thiago (AT) kde.org
    PGP/GPG: 0x6EF45358; fingerprint:
    E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358

3. Ac seo woruld wearð geborod, swá se Scieppend cwæð "Gewurde Unix" and 
wundor fremede and him "Unix" genemned, þæt is se rihtendgesamnung.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20050813/68e53533/attachment.sig>


More information about the kde-core-devel mailing list