diff options
author | Timothy Pearson <[email protected]> | 2012-12-06 16:47:27 -0600 |
---|---|---|
committer | Timothy Pearson <[email protected]> | 2012-12-06 16:47:27 -0600 |
commit | 78125ea2f051107b84fdc0354acdedb7885308ee (patch) | |
tree | c162d7f55467f81a01e2e669ce297acce06b3947 /src/kernel/qeventloop.cpp | |
parent | 7aa5ac7f0e76c5b87e4ca837b75b3edd522a3372 (diff) | |
download | qt3-78125ea2f051107b84fdc0354acdedb7885308ee.tar.gz qt3-78125ea2f051107b84fdc0354acdedb7885308ee.zip |
Add real threading support, including per-thread event loops, to QThread
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 } /*! |