diff options
Diffstat (limited to 'src/kernel/qeventloop.cpp')
-rw-r--r-- | src/kernel/qeventloop.cpp | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/src/kernel/qeventloop.cpp b/src/kernel/qeventloop.cpp index 1f6a130..5eadb9e 100644 --- a/src/kernel/qeventloop.cpp +++ b/src/kernel/qeventloop.cpp @@ -41,6 +41,11 @@ #include "qapplication.h" #include "qdatetime.h" +#ifdef QT_THREAD_SUPPORT +# include "qthread.h" +# include "qthreadinstance_p.h" +#endif + /*! \class QEventLoop \brief The QEventLoop class manages the event queue. @@ -100,15 +105,27 @@ QEventLoop::QEventLoop( QObject *parent, const char *name ) : QObject( parent, name ) { #if defined(QT_CHECK_STATE) - if ( QApplication::eventloop ) - qFatal( "QEventLoop: there must be only one event loop object. \nConstruct it before QApplication." ); - // for now ;) + if ( QApplication::currentEventLoop() ) + qFatal( "QEventLoop: there must be only one event loop object per thread. \nIf this is supposed to be the main GUI event loop, construct it before QApplication." ); + if (!QThread::currentThreadObject()) { + qFatal( "QEventLoop: this object can only be used in threads constructed via QThread." ); + } #endif // QT_CHECK_STATE d = new QEventLoopPrivate; init(); + +#ifdef QT_THREAD_SUPPORT + QThread* thread = QThread::currentThreadObject(); + if (thread) { + if (thread->d) { + thread->d->eventLoop = this; + } + } +#else QApplication::eventloop = this; +#endif } /*! @@ -118,7 +135,16 @@ QEventLoop::~QEventLoop() { cleanup(); delete d; +#ifdef QT_THREAD_SUPPORT + QThread* thread = QThread::currentThreadObject(); + if (thread) { + if (thread->d) { + thread->d->eventLoop = 0; + } + } +#else QApplication::eventloop = 0; +#endif } /*! |