From 8e1cc7043ff53353187f5617af9b75d49e802013 Mon Sep 17 00:00:00 2001 From: Andrew Knight Date: Tue, 28 Jan 2014 13:00:17 +0200 Subject: Fix WinRT timer dispatch This fixes the event dispatcher lookup on timer callbacks, which was incorrectly using only the gui event dispatcher to look up timers. Change-Id: Ia01a07f6505afd0adfc0641e9c60199f258138a1 Reviewed-by: Oliver Wolff --- src/corelib/kernel/qeventdispatcher_winrt.cpp | 34 +++++++++++++-------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'src/corelib/kernel') diff --git a/src/corelib/kernel/qeventdispatcher_winrt.cpp b/src/corelib/kernel/qeventdispatcher_winrt.cpp index 8639e925cd..cd843a4986 100644 --- a/src/corelib/kernel/qeventdispatcher_winrt.cpp +++ b/src/corelib/kernel/qeventdispatcher_winrt.cpp @@ -94,16 +94,7 @@ public: private: - static HRESULT timerExpiredCallback(ABI::Windows::System::Threading::IThreadPoolTimer *source); - static int idForTimer(IThreadPoolTimer *timer) - { - QAbstractEventDispatcher *eventDispatcher = QCoreApplication::eventDispatcher(); - if (!eventDispatcher) - return -1; - if (QEventDispatcherWinRTPrivate *that = static_cast(get(eventDispatcher))) - return that->timerIds.value(timer, -1); - return -1; - } + static HRESULT timerExpiredCallback(IThreadPoolTimer *timer); QHash timerDict; QHash timerIds; @@ -365,8 +356,8 @@ void QEventDispatcherWinRTPrivate::registerTimer(WinRTTimerInfo *t) void QEventDispatcherWinRTPrivate::unregisterTimer(WinRTTimerInfo *t) { if (t->timer) { - t->timer->Cancel(); timerIds.remove(t->timer.Get()); + t->timer->Cancel(); } timerDict.remove(t->id); delete t; @@ -389,13 +380,22 @@ void QEventDispatcherWinRTPrivate::sendTimerEvent(int timerId) } } -HRESULT QEventDispatcherWinRTPrivate::timerExpiredCallback(IThreadPoolTimer *source) +HRESULT QEventDispatcherWinRTPrivate::timerExpiredCallback(IThreadPoolTimer *timer) { - int timerId = idForTimer(source); - if (timerId > 0) - QCoreApplication::postEvent(QCoreApplication::eventDispatcher(), new QTimerEvent(timerId)); - else - qWarning("QEventDispatcherWinRT::timerExpiredCallback: Could not find timer %d in timer list", source); + QThread *thread = QThread::currentThread(); + if (!thread) + return E_FAIL; + + QAbstractEventDispatcher *eventDispatcher = thread->eventDispatcher(); + if (!eventDispatcher) + return E_FAIL; + + QEventDispatcherWinRTPrivate *d = static_cast(get(eventDispatcher)); + int timerId = d->timerIds.value(timer, -1); + if (timerId < 0) + return E_FAIL; // A callback was received after the timer was canceled + + QCoreApplication::postEvent(eventDispatcher, new QTimerEvent(timerId)); return S_OK; } -- cgit v1.2.3