From 6c4f5ecef0c9bc8bfb31ef4099d53ba02f0611aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Tue, 13 Feb 2018 17:11:50 +0100 Subject: [PATCH] Share event dispatcher creation between QThreadPrivate and QCoreApplication A step towards having the application do its event dispatching though the thread data's dispatcher, like QEventLoop, instead of keeping two references to the same dispatcher, one in QCoreApplicationPrivate and one in QThreadData. Change-Id: I7b215e7e99869d25638ec67f0666f632a508cc0f Reviewed-by: Thiago Macieira --- src/corelib/kernel/qcoreapplication.cpp | 27 ++++--------------------- src/corelib/thread/qthread_unix.cpp | 3 ++- 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index ef431baca63..4e32f909643 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -538,29 +538,10 @@ void QCoreApplicationPrivate::cleanupThreadData() void QCoreApplicationPrivate::createEventDispatcher() { Q_Q(QCoreApplication); -#if defined(Q_OS_UNIX) -# if defined(Q_OS_DARWIN) - bool ok = false; - int value = qEnvironmentVariableIntValue("QT_EVENT_DISPATCHER_CORE_FOUNDATION", &ok); - if (ok && value > 0) - eventDispatcher = new QEventDispatcherCoreFoundation(q); - else - eventDispatcher = new QEventDispatcherUNIX(q); -# elif !defined(QT_NO_GLIB) - if (qEnvironmentVariableIsEmpty("QT_NO_GLIB") && QEventDispatcherGlib::versionSupported()) - eventDispatcher = new QEventDispatcherGlib(q); - else - eventDispatcher = new QEventDispatcherUNIX(q); -# else - eventDispatcher = new QEventDispatcherUNIX(q); -# endif -#elif defined(Q_OS_WINRT) - eventDispatcher = new QEventDispatcherWinRT(q); -#elif defined(Q_OS_WIN) - eventDispatcher = new QEventDispatcherWin32(q); -#else -# error "QEventDispatcher not yet ported to this platform" -#endif + QThreadData *data = QThreadData::current(); + Q_ASSERT(!data->hasEventDispatcher()); + eventDispatcher = QThreadPrivate::createEventDispatcher(data); + eventDispatcher->setParent(q); } void QCoreApplicationPrivate::eventDispatcherReady() diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp index 2c815b870a2..6248842d78d 100644 --- a/src/corelib/thread/qthread_unix.cpp +++ b/src/corelib/thread/qthread_unix.cpp @@ -296,8 +296,9 @@ QAbstractEventDispatcher *QThreadPrivate::createEventDispatcher(QThreadData *dat else return new QEventDispatcherUNIX; #elif !defined(QT_NO_GLIB) + const bool isQtMainThread = data->thread == QCoreApplicationPrivate::mainThread(); if (qEnvironmentVariableIsEmpty("QT_NO_GLIB") - && qEnvironmentVariableIsEmpty("QT_NO_THREADED_GLIB") + && (isQtMainThread || qEnvironmentVariableIsEmpty("QT_NO_THREADED_GLIB")) && QEventDispatcherGlib::versionSupported()) return new QEventDispatcherGlib; else