From 302e6968f1152d5dee8d5debafb313bd53fa55ff Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Mon, 4 Jun 2012 21:51:04 +0200 Subject: statemachine: Make delayed event posting work from secondary thread postDelayedEvent() and cancelDelayedEvent() are marked as thread-safe in the documentation. Unfortunately, they didn't actually work when called from another thread; they just produced some warnings: QObject::startTimer: timers cannot be started from another thread QObject::killTimer: timers cannot be stopped from another thread As the warnings indicate, the issue was that postDelayedEvent() (cancelDelayedEvent()) unconditionally called QObject::startTimer() (stopTimer()), i.e. without considering which thread the function was called from. If the function is called from a different thread, the actual starting/stopping of the associated timer is now done from the correct thread, by asynchronously calling a private slot on the state machine. This also means that the raw timer id can no longer be used as the id of the delayed event, since a valid event id must be returned before the timer has started. The state machine now manages those ids itself (using a QFreeList, just like startTimer() and killTimer() do), and also keeps a mapping from timer id to event id once the timer has been started. This is inherently more complex than before, but at least the API should work as advertised/intended now. Task-number: QTBUG-17975 Change-Id: I3a866d01dca23174c8841112af50b87141df0943 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/corelib/statemachine/qstatemachine.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/corelib/statemachine/qstatemachine.h') diff --git a/src/corelib/statemachine/qstatemachine.h b/src/corelib/statemachine/qstatemachine.h index b3aeb41016..bc3f2fa27f 100644 --- a/src/corelib/statemachine/qstatemachine.h +++ b/src/corelib/statemachine/qstatemachine.h @@ -184,6 +184,8 @@ private: #ifndef QT_NO_ANIMATION Q_PRIVATE_SLOT(d_func(), void _q_animationFinished()) #endif + Q_PRIVATE_SLOT(d_func(), void _q_startDelayedEventTimer(int, int)) + Q_PRIVATE_SLOT(d_func(), void _q_killDelayedEventTimer(int, int)) }; #endif //QT_NO_STATEMACHINE -- cgit v1.2.3