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 <oliver.wolff@digia.com>
This commit is contained in:
parent
8e26730fb7
commit
8e1cc7043f
@ -94,16 +94,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static HRESULT timerExpiredCallback(ABI::Windows::System::Threading::IThreadPoolTimer *source);
|
static HRESULT timerExpiredCallback(IThreadPoolTimer *timer);
|
||||||
static int idForTimer(IThreadPoolTimer *timer)
|
|
||||||
{
|
|
||||||
QAbstractEventDispatcher *eventDispatcher = QCoreApplication::eventDispatcher();
|
|
||||||
if (!eventDispatcher)
|
|
||||||
return -1;
|
|
||||||
if (QEventDispatcherWinRTPrivate *that = static_cast<QEventDispatcherWinRTPrivate *>(get(eventDispatcher)))
|
|
||||||
return that->timerIds.value(timer, -1);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
QHash<int, WinRTTimerInfo*> timerDict;
|
QHash<int, WinRTTimerInfo*> timerDict;
|
||||||
QHash<IThreadPoolTimer *, int> timerIds;
|
QHash<IThreadPoolTimer *, int> timerIds;
|
||||||
@ -365,8 +356,8 @@ void QEventDispatcherWinRTPrivate::registerTimer(WinRTTimerInfo *t)
|
|||||||
void QEventDispatcherWinRTPrivate::unregisterTimer(WinRTTimerInfo *t)
|
void QEventDispatcherWinRTPrivate::unregisterTimer(WinRTTimerInfo *t)
|
||||||
{
|
{
|
||||||
if (t->timer) {
|
if (t->timer) {
|
||||||
t->timer->Cancel();
|
|
||||||
timerIds.remove(t->timer.Get());
|
timerIds.remove(t->timer.Get());
|
||||||
|
t->timer->Cancel();
|
||||||
}
|
}
|
||||||
timerDict.remove(t->id);
|
timerDict.remove(t->id);
|
||||||
delete t;
|
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);
|
QThread *thread = QThread::currentThread();
|
||||||
if (timerId > 0)
|
if (!thread)
|
||||||
QCoreApplication::postEvent(QCoreApplication::eventDispatcher(), new QTimerEvent(timerId));
|
return E_FAIL;
|
||||||
else
|
|
||||||
qWarning("QEventDispatcherWinRT::timerExpiredCallback: Could not find timer %d in timer list", source);
|
QAbstractEventDispatcher *eventDispatcher = thread->eventDispatcher();
|
||||||
|
if (!eventDispatcher)
|
||||||
|
return E_FAIL;
|
||||||
|
|
||||||
|
QEventDispatcherWinRTPrivate *d = static_cast<QEventDispatcherWinRTPrivate *>(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;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user