> > 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.
Aha, this does make a lot of sense, thanks this is very useful to know :) Andy _______________________________________________ Development mailing list Development@qt-project.org http://lists.qt-project.org/mailman/listinfo/development