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 <thiago.macieira@intel.com>
This commit is contained in:
Morten Johan Sørvig 2015-07-01 09:57:33 +02:00 committed by Timur Pocheptsov
parent ff4d8906f6
commit 97c8f6aa9c
2 changed files with 27 additions and 6 deletions

View File

@ -70,6 +70,9 @@
# include "qeventdispatcher_blackberry_p.h"
# include <process.h>
# include <unistd.h>
# elif defined(Q_OS_OSX)
# include "qeventdispatcher_cf_p.h"
# include "qeventdispatcher_unix_p.h"
# else
# if !defined(QT_NO_GLIB)
# include "qeventdispatcher_glib_p.h"
@ -505,12 +508,19 @@ void QCoreApplicationPrivate::createEventDispatcher()
#if defined(Q_OS_UNIX)
# if defined(Q_OS_BLACKBERRY)
eventDispatcher = new QEventDispatcherBlackberry(q);
# 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)
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
# endif
eventDispatcher = new QEventDispatcherUNIX(q);
# else
eventDispatcher = new QEventDispatcherUNIX(q);
# endif
#elif defined(Q_OS_WINRT)

View File

@ -36,9 +36,13 @@
#include "qplatformdefs.h"
#include <private/qcoreapplication_p.h>
#include <private/qcore_unix_p.h>
#if defined(Q_OS_BLACKBERRY)
# include <private/qeventdispatcher_blackberry_p.h>
#elif defined(Q_OS_OSX)
# include <private/qeventdispatcher_cf_p.h>
# include <private/qeventdispatcher_unix_p.h>
#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