From 97c8f6aa9c774aa0aac8948dd619e93944ec104a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Wed, 1 Jul 2015 09:57:33 +0200 Subject: OS X: Add opt-in for CoreFoundation event dispatcher Opt-in by setting QT_EVENT_DISPATCHER_CORE_FOUNDATION=1 This will make QCoreApplication and QThread create a QEventDispatcherCoreFoundation instead of a QEventDispatcherUNIX. With this change we can now support calling native API that requires a running Core Foundation event loop on the QCoreApplication main thread and secondary threads. Previously this was only supported on the QGuiApplication main thread. Rewrite the #ifdef event dispatcher logic slightly: both OSX and GLIB now gets an "else" branch for the UNIX event dispatcher, instead of the current "dangling else" pattern which only works for one #ifdef case. Change-Id: If853567fa097fe007502b0804c2307a989719866 Task-number: QTBUG-46625 Task-number: QTBUG-48758 Reviewed-by: Thiago Macieira --- src/corelib/thread/qthread_unix.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/corelib/thread/qthread_unix.cpp') diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp index c340915d35..af4ce7c59e 100644 --- a/src/corelib/thread/qthread_unix.cpp +++ b/src/corelib/thread/qthread_unix.cpp @@ -36,9 +36,13 @@ #include "qplatformdefs.h" #include +#include #if defined(Q_OS_BLACKBERRY) # include +#elif defined(Q_OS_OSX) +# include +# include #else # if !defined(QT_NO_GLIB) # include "../kernel/qeventdispatcher_glib_p.h" @@ -248,14 +252,21 @@ void QThreadPrivate::createEventDispatcher(QThreadData *data) { #if defined(Q_OS_BLACKBERRY) data->eventDispatcher.storeRelease(new QEventDispatcherBlackberry); -#else -#if !defined(QT_NO_GLIB) +# elif defined(Q_OS_OSX) + bool ok = false; + int value = qEnvironmentVariableIntValue("QT_EVENT_DISPATCHER_CORE_FOUNDATION", &ok); + if (ok && value > 0) + data->eventDispatcher.storeRelease(new QEventDispatcherCoreFoundation); + else + data->eventDispatcher.storeRelease(new QEventDispatcherUNIX); +# elif !defined(QT_NO_GLIB) if (qEnvironmentVariableIsEmpty("QT_NO_GLIB") && qEnvironmentVariableIsEmpty("QT_NO_THREADED_GLIB") && QEventDispatcherGlib::versionSupported()) data->eventDispatcher.storeRelease(new QEventDispatcherGlib); else -#endif + data->eventDispatcher.storeRelease(new QEventDispatcherUNIX); +#else data->eventDispatcher.storeRelease(new QEventDispatcherUNIX); #endif -- cgit v1.2.3