[Qt-interest] QObject::deleteLater and private event loop (not using QCoreApplication::exec())

Nikos Chantziaras realnc at arcor.de
Sat Jun 11 18:02:57 CEST 2011


On 06/10/2011 04:22 PM, Bo Thorsen wrote:
> Den 10-06-2011 14:19, Nikos Chantziaras skrev:
>> Then why call deleteLater() in the first place? Only call it when
>> you're done with the object.
>
> I use deleteLater for two things: Connecting signals to it (like
> finished()) and as a substitute for "delete this" in slots.
>
> But I also use it to substitute this kind of code:
>
> const bool shouldDelete = something();
> ... // code that uses this object
> if (shouldDelete)
> delete this;
>
> with
>
> deleteLater();
> ... // code that uses this object
>
> It's a nice tool for what it does. I could certainly develop without it,
> but why would I?

Ah, this makes sense.  I never needed to delete an object from within 
itself.  I always considered this was a bad idea.  But nice to know that 
deleteLater() can be used for this.



More information about the Qt-interest-old mailing list