diff --git a/include/wx/qt/evtloop.h b/include/wx/qt/evtloop.h index bb725e63d8..dbdbd6a5a0 100644 --- a/include/wx/qt/evtloop.h +++ b/include/wx/qt/evtloop.h @@ -9,6 +9,7 @@ #define _WX_QT_EVTLOOP_H_ class QTimer; +class QEventLoop; class WXDLLIMPEXP_CORE wxQtEventLoopBase : public wxEventLoopBase { @@ -32,6 +33,7 @@ public: protected: private: + QEventLoop *m_qtEventLoop; QTimer *m_qtIdleTimer; wxDECLARE_NO_COPY_CLASS(wxQtEventLoopBase); diff --git a/src/qt/evtloop.cpp b/src/qt/evtloop.cpp index 3a6bd2e6b7..132d6533c2 100644 --- a/src/qt/evtloop.cpp +++ b/src/qt/evtloop.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include @@ -56,7 +57,7 @@ void wxQtIdleTimer::idle() // Process pending events if ( wxTheApp ) wxTheApp->ProcessPendingEvents(); - + // Send idle event if ( m_eventLoop->ProcessIdle() ) m_eventLoop->ScheduleIdleCheck(); @@ -77,11 +78,15 @@ wxQtEventLoopBase::wxQtEventLoopBase() // Pass all events to the idle timer, so it can be restarted each time // an event is received qApp->installEventFilter( m_qtIdleTimer ); + + + m_qtEventLoop = new QEventLoop; } wxQtEventLoopBase::~wxQtEventLoopBase() { qApp->removeEventFilter(m_qtIdleTimer); + delete m_qtEventLoop; delete m_qtIdleTimer; } @@ -89,44 +94,31 @@ void wxQtEventLoopBase::ScheduleExit(int rc) { wxCHECK_RET( IsInsideRun(), wxT("can't call ScheduleExit() if not started") ); m_shouldExit = true; - QCoreApplication::exit( rc ); + m_qtEventLoop->exit(rc); } int wxQtEventLoopBase::DoRun() { - int ret; - - // This is placed inside of a loop to take into account nested event loops - while ( !m_shouldExit ) - { - // This will print Qt warnins if app already started: - // "QCoreApplication::exec: The event loop is already running" - // TODO: check the loopLevel (nested) like in wxGTK - ret = QCoreApplication::exec(); - // process pending events (if exec was started previously) - // TODO: use a real new QEventLoop() ? - QCoreApplication::processEvents(); - } + const int ret = m_qtEventLoop->exec(); OnExit(); return ret; } bool wxQtEventLoopBase::Pending() const { - return QCoreApplication::hasPendingEvents(); + QAbstractEventDispatcher *instance = QAbstractEventDispatcher::instance(); + return instance->hasPendingEvents(); } bool wxQtEventLoopBase::Dispatch() { - QCoreApplication::processEvents(); - + m_qtEventLoop->processEvents(); return true; } int wxQtEventLoopBase::DispatchTimeout(unsigned long timeout) { - QCoreApplication::processEvents( QEventLoop::AllEvents, timeout ); - + m_qtEventLoop->processEvents(QEventLoop::AllEvents, timeout); return true; }