--- qt-opensource-4.8.0.old/src/gui/kernel/qeventdispatcher_x11.cpp 2011-12-08 00:06:02.000000000 -0500 +++ qt-opensource-4.8.0.new/src/gui/kernel/qeventdispatcher_x11.cpp 2011-12-30 01:40:44.188018115 -0500 @@ -46,9 +46,20 @@ #include "qt_x11_p.h" #include +#include QT_BEGIN_NAMESPACE +class QScopedLoopLevelIncrementer { + QThreadData *threadData; +public: + QScopedLoopLevelIncrementer(QThreadData *threadData) + : threadData(threadData) + { ++threadData->loopLevel; } + ~QScopedLoopLevelIncrementer() + { --threadData->loopLevel; } +}; + class QEventDispatcherX11Private : public QEventDispatcherUNIXPrivate { Q_DECLARE_PUBLIC(QEventDispatcherX11) @@ -123,11 +134,16 @@ bool QEventDispatcherX11::processEvents( // no event to process break; } - - // send through event filter - if (filterEvent(&event)) - continue; - + { + // Raise the loopLevel here so that deleteLater() calls in or triggered + // by filterEvent() will be processed in a reasonably timely manner from + // the main event loop. Not raising loopLevel here may result in such + // deleteLater() calls not being processed until the applciation exits. + QScopedLoopLevelIncrementer loopLevelIncrementer(d->threadData); + // send through event filter + if (filterEvent(&event)) + continue; + } nevents++; if (qApp->x11ProcessEvent(&event) == 1) return true;