From 6bab6fccd2d8ee8e83e968864d729c1bbee39a66 Mon Sep 17 00:00:00 2001 From: John Stanley Date: Mon, 30 Jan 2012 07:27:49 -0500 Subject: Raise loopLevel for deleteLater in event filters Change-Id: I163f510f6e99d86a35cc78965fa383e7f4618f42 Reviewed-by: Bradley T. Hughes --- src/corelib/kernel/qabstracteventdispatcher.cpp | 6 +++++- src/corelib/thread/qthread_p.h | 11 +++++++++++ src/gui/kernel/qapplication_p.h | 11 ----------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/corelib/kernel/qabstracteventdispatcher.cpp b/src/corelib/kernel/qabstracteventdispatcher.cpp index 3f73e61..3b0a258 100644 --- a/src/corelib/kernel/qabstracteventdispatcher.cpp +++ b/src/corelib/kernel/qabstracteventdispatcher.cpp @@ -532,8 +532,12 @@ QAbstractEventDispatcher::EventFilter QAbstractEventDispatcher::setEventFilter(E bool QAbstractEventDispatcher::filterEvent(void *message) { Q_D(QAbstractEventDispatcher); - if (d->event_filter) + if (d->event_filter) { + // Raise the loopLevel so that deleteLater() calls in or triggered + // by event_filter() will be processed from the main event loop. + QScopedLoopLevelCounter loopLevelCounter(d->threadData); return d->event_filter(message); + } return false; } diff --git a/src/corelib/thread/qthread_p.h b/src/corelib/thread/qthread_p.h index 9b71d02..bb90de7 100644 --- a/src/corelib/thread/qthread_p.h +++ b/src/corelib/thread/qthread_p.h @@ -238,6 +238,17 @@ public: # endif }; +class QScopedLoopLevelCounter +{ + QThreadData *threadData; +public: + inline QScopedLoopLevelCounter(QThreadData *threadData) + : threadData(threadData) + { ++threadData->loopLevel; } + inline ~QScopedLoopLevelCounter() + { --threadData->loopLevel; } +}; + // thread wrapper for the main() thread class QAdoptedThread : public QThread { diff --git a/src/gui/kernel/qapplication_p.h b/src/gui/kernel/qapplication_p.h index 9acf2c8..31d0b75 100644 --- a/src/gui/kernel/qapplication_p.h +++ b/src/gui/kernel/qapplication_p.h @@ -277,17 +277,6 @@ typedef struct tagGESTURECONFIG #endif // Q_WS_WIN -class QScopedLoopLevelCounter -{ - QThreadData *threadData; -public: - QScopedLoopLevelCounter(QThreadData *threadData) - : threadData(threadData) - { ++threadData->loopLevel; } - ~QScopedLoopLevelCounter() - { --threadData->loopLevel; } -}; - typedef QHash FontHash; FontHash *qt_app_fonts_hash(); -- cgit v0.12