[Development] Question about deferred delete handling in sendPostedEvents

Thiago Macieira thiago.macieira at intel.com
Mon Feb 17 19:39:10 CET 2014


Em seg 17 fev 2014, às 14:35:08, Shaw Andy escreveu:
> Hi,
> 
> I was looking at a problem regarding deferred deletes causing a crash inside
> nested loops and it was pointed out that in
> QCoreApplication::setPostedEvents() there is some code there that
> determines whether it is safe to delete the object or not. From my
> understanding it will only delete an object if the loop level that it was
> called from is greater than the current one. However it seems that if the
> loop level is 0 (i.e. main event loop I guess) and the current one is
> higher than 0 it deletes anyway, is this the correct intention? Does anyone
> know why this is safe if so?
> 
> For reference the code is this bit specifically:
> 
>             const bool allowDeferredDelete =
>                 (loopLevel > data->loopLevel
> 
>                  || (!loopLevel && data->loopLevel > 0)
>                  || (event_type == QEvent::DeferredDelete
> 
>                      && loopLevel == data->loopLevel));
> 
> Where loopLevel is 0 but data->loopLevel is greater than 0.

Loop level equal to 0 means the object was deleteLater'ed in main(), before 
exec(). That is, when no event loop was started. That means any event loop 
level can delete it.

Otherwise, the object is only deleted if you're running a loop with equal or 
*lower* nesting level than when it was deleteLater'ed.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Development mailing list