[Qt-interest] QObject::deleteLater and private event loop (not using QCoreApplication::exec())
Kishore
kitts.mailinglists at gmail.com
Sat Jun 11 08:32:01 CEST 2011
On Friday 10 Jun 2011 3:19:33 PM Nikos Chantziaras wrote:
> On 06/10/2011 02:53 PM, Bo Thorsen wrote:
> > Den 10-06-2011 13:27, Nikos Chantziaras skrev:
> >> On 06/10/2011 11:45 AM, Thiago Macieira wrote:
> >>> [...]
> >>> deleteLater() events (DeferredDelete) are handled specially, to
> >>> avoid
> >>> something like:
> >>>
> >>> obj->deleteLater();
> >>> obj->something();
> >>> run a dialog
> >>> obj->somethingElse(); // crash here
> >>
> >> Just out of curiosity, why would anyone try to avoid the above? It
> >> looks exactly like trying to avoid:
> >>
> >> delete obj;
> >> obj->something();
> >>
> >> It's the same kind of coding mistake.
> >
> > Not exactly. The point of deleteLater is that you know the object will
> > be deleted some time after the function returned - how long exactly is
> > irrelevant.
>
> It doesn't look very irrelevant to me though, simply because of the
> nature of the word "irrelevant." Meaning that once you call
> deleteLater(), you shouldn't call anything else on that object since you
> don't know when it's going to be deleted.
But it is guaranteed to last at least till the function returns. The actual
deletion only happens after the function returns till it gets to the event
loop from which it was called in the first place.
--
Cheers!
Kishore
More information about the Qt-interest-old
mailing list