From 2b7d98ef8fbd6cf49326fa0bbf154e9bacbb7b49 Mon Sep 17 00:00:00 2001 From: Sven Anderson Date: Thu, 8 Sep 2011 17:40:55 +0200 Subject: Allow to create a custom event dispatcher for specific QThreads. QAbstractEventDispatcher() does no longer install itself into the current thread. Instead the new methods QThread::setEventDispatcher() and QCoreApplication::setEventDispatcher() allow to install a custom event dispatcher into any QThread as long as there is no default event dispatcher created yet. That is, before the thread has been started with QThread::start() or, in case of the main thread, before QCoreApplication has been instantiated. Change-Id: I7367e13d8d8aebed5a5651260bb69b8818eb1b90 Reviewed-by: Olivier Goffart Reviewed-by: Bradley T. Hughes --- src/corelib/kernel/qabstracteventdispatcher.cpp | 29 +++++-------------------- 1 file changed, 6 insertions(+), 23 deletions(-) (limited to 'src/corelib/kernel/qabstracteventdispatcher.cpp') diff --git a/src/corelib/kernel/qabstracteventdispatcher.cpp b/src/corelib/kernel/qabstracteventdispatcher.cpp index 10de2caf62..b936ac4ed2 100644 --- a/src/corelib/kernel/qabstracteventdispatcher.cpp +++ b/src/corelib/kernel/qabstracteventdispatcher.cpp @@ -49,16 +49,6 @@ QT_BEGIN_NAMESPACE -void QAbstractEventDispatcherPrivate::init() -{ - Q_Q(QAbstractEventDispatcher); - if (threadData->eventDispatcher != 0) { - qWarning("QAbstractEventDispatcher: An event dispatcher has already been created for this thread"); - } else { - threadData->eventDispatcher = q; - } -} - // we allow for 2^24 = 8^8 = 16777216 simultaneously running timers struct QtTimerIdFreeListConstants : public QFreeListDefaultConstants { @@ -127,8 +117,9 @@ void QAbstractEventDispatcherPrivate::releaseTimerId(int timerId) instance() and call functions on the QAbstractEventDispatcher object that is returned. If you want to use your own instance of QAbstractEventDispatcher or of a QAbstractEventDispatcher - subclass, you must create your instance \e before you create the - QApplication object. + subclass, you must install it with QCoreApplication::setEventDispatcher() + or QThread::setEventDispatcher() \e before a default event dispatcher has + been installed. The main event loop is started by calling QCoreApplication::exec(), and stopped by calling @@ -145,29 +136,21 @@ void QAbstractEventDispatcherPrivate::releaseTimerId(int timerId) reimplementation of QAbstractEventDispatcher that merges Qt and Motif events together. - \sa QEventLoop, QCoreApplication + \sa QEventLoop, QCoreApplication, QThread */ /*! Constructs a new event dispatcher with the given \a parent. */ QAbstractEventDispatcher::QAbstractEventDispatcher(QObject *parent) - : QObject(*new QAbstractEventDispatcherPrivate, parent) -{ - Q_D(QAbstractEventDispatcher); - d->init(); -} + : QObject(*new QAbstractEventDispatcherPrivate, parent) {} /*! \internal */ QAbstractEventDispatcher::QAbstractEventDispatcher(QAbstractEventDispatcherPrivate &dd, QObject *parent) - : QObject(dd, parent) -{ - Q_D(QAbstractEventDispatcher); - d->init(); -} + : QObject(dd, parent) {} /*! Destroys the event dispatcher. -- cgit v1.2.3