QStateMachine: allow posting of events when starting.
This allows subclasses to submit any queued events that have to be handled before normal operation starts. For example, if an error event got generated during initialization which has to be handled by the state machine, the startup hook in the private class can be used to post those events and have the state machine handle them appropriately. Change-Id: I62249a31d8840f47bc19920870ad5da9647e61f9 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
This commit is contained in:
parent
eb4bf7df60
commit
92c2783f77
@ -1845,6 +1845,8 @@ void QStateMachinePrivate::_q_start()
|
||||
|
||||
registerMultiThreadedSignalTransitions();
|
||||
|
||||
startupHook();
|
||||
|
||||
#ifdef QSTATEMACHINE_DEBUG
|
||||
qDebug() << q << ": starting";
|
||||
#endif
|
||||
@ -2114,6 +2116,10 @@ void QStateMachinePrivate::emitStateFinished(QState *forState, QFinalState *guil
|
||||
QStatePrivate::get(forState)->emitFinished();
|
||||
}
|
||||
|
||||
void QStateMachinePrivate::startupHook()
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
This function is called when the state machine is performing no
|
||||
microstep because no transition is enabled (i.e. an event is ignored).
|
||||
@ -2726,14 +2732,18 @@ void QStateMachine::setRunning(bool running)
|
||||
event queue. Events are processed in the order posted. The state machine
|
||||
takes ownership of the event and deletes it once it has been processed.
|
||||
|
||||
You can only post events when the state machine is running.
|
||||
You can only post events when the state machine is running or when it is starting up.
|
||||
|
||||
\sa postDelayedEvent()
|
||||
*/
|
||||
void QStateMachine::postEvent(QEvent *event, EventPriority priority)
|
||||
{
|
||||
Q_D(QStateMachine);
|
||||
if (d->state != QStateMachinePrivate::Running) {
|
||||
switch (d->state) {
|
||||
case QStateMachinePrivate::Running:
|
||||
case QStateMachinePrivate::Starting:
|
||||
break;
|
||||
default:
|
||||
qWarning("QStateMachine::postEvent: cannot post event when the state machine is not running");
|
||||
return;
|
||||
}
|
||||
|
@ -202,6 +202,7 @@ public:
|
||||
void cancelAllDelayedEvents();
|
||||
|
||||
virtual void emitStateFinished(QState *forState, QFinalState *guiltyState);
|
||||
virtual void startupHook();
|
||||
|
||||
#ifndef QT_NO_PROPERTIES
|
||||
class RestorableId {
|
||||
|
Loading…
Reference in New Issue
Block a user