iOS: implement QEventLoop support in the event dispatcher

With this patch you can now expect the following code to work:

QEventLoop l;
QTimer::singleShot(1000, &l, SLOT(quit()));
l.exec();

Change-Id: Ic73e37affaadf8a859787d84ac02c15621ac7a29
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@digia.com>
bb10
Richard Moe Gustavsen 2012-11-07 16:34:43 +01:00 committed by Tor Arne Vestbø
parent 19de726725
commit ea1e5ccd62
2 changed files with 8 additions and 2 deletions

View File

@ -108,6 +108,8 @@ public:
void flush();
private:
bool m_interrupted;
CFRunLoopSourceRef m_postedEventsRunLoopSource;
CFRunLoopSourceRef m_blockingTimerRunLoopSource;

View File

@ -152,6 +152,7 @@ void QIOSEventDispatcher::processPostedEvents()
QIOSEventDispatcher::QIOSEventDispatcher(QObject *parent)
: QAbstractEventDispatcher(parent)
, m_interrupted(false)
, m_runLoopTimerRef(0)
{
CFRunLoopRef mainRunLoop = CFRunLoopGetMain();
@ -187,6 +188,8 @@ QIOSEventDispatcher::~QIOSEventDispatcher()
bool QIOSEventDispatcher::processEvents(QEventLoop::ProcessEventsFlags flags)
{
m_interrupted = false;
UIApplication *uiApplication = [UIApplication sharedApplication];
bool excludeUserEvents = flags & QEventLoop::ExcludeUserInputEvents;
bool execFlagSet = (flags & QEventLoop::DialogExec) || (flags & QEventLoop::EventLoopExec);
@ -201,7 +204,8 @@ bool QIOSEventDispatcher::processEvents(QEventLoop::ProcessEventsFlags flags)
return UIApplicationMain(qAppPriv->argc, qAppPriv->argv, nil, NSStringFromClass([QIOSApplicationDelegate class]));
}
} else {
// todo: start NSRunLoop...
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
while ([runLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]] && !m_interrupted);
}
} else {
// todo: manual processEvents...
@ -309,7 +313,7 @@ void QIOSEventDispatcher::wakeUp()
void QIOSEventDispatcher::interrupt()
{
qDebug() << __FUNCTION__ << "not implemented";
m_interrupted = true;
}
void QIOSEventDispatcher::flush()