diff options
author | Kent Hansen <kent.hansen@nokia.com> | 2012-05-31 13:33:14 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-06-04 16:53:42 +0200 |
commit | f7c2ba9bbe764a3f21da3fdc6a1e1c6c6da85a8f (patch) | |
tree | 6ecbd3442e7a78292842bc4bc0c6333501a54211 | |
parent | 268216570881cfc7d066d8183047d05829e1248b (diff) |
Enter initial state before QStateMachine::started() is emitted
The documentation says that started() "is emitted when the state
machine has entered its initial state", but the implementation
didn't adhere to that.
The consequence is that if you e.g. emitted a signal from a slot
connected to started(), and that signal was used by a transition
from the initial state, the signal would effectively get ignored and
the state machine would remain in the initial state.
Task-number: QTBUG-24307
Change-Id: Ibbeb627d517eaff821d88e256a949eacf6aae350
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
-rw-r--r-- | src/corelib/statemachine/qstatemachine.cpp | 4 | ||||
-rw-r--r-- | tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp | 18 |
2 files changed, 21 insertions, 1 deletions
diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp index fd190abc01..ffe2e74d61 100644 --- a/src/corelib/statemachine/qstatemachine.cpp +++ b/src/corelib/statemachine/qstatemachine.cpp @@ -1203,7 +1203,6 @@ void QStateMachinePrivate::_q_start() #endif state = Running; processingScheduled = true; // we call _q_process() below - emit q->started(); QState *start = startState(); Q_ASSERT(start != 0); @@ -1230,6 +1229,9 @@ void QStateMachinePrivate::_q_start() #ifdef QSTATEMACHINE_DEBUG qDebug() << q << ": initial configuration:" << configuration; #endif + + emit q->started(); + _q_process(); } diff --git a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp index df6ac88f47..34e9b742b1 100644 --- a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp +++ b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp @@ -175,6 +175,8 @@ private slots: void stopInTransitionToFinalState(); void stopInEventTest_data(); void stopInEventTest(); + + void initialStateIsEnteredBeforeStartedEmitted(); }; class TestState : public QState @@ -3906,5 +3908,21 @@ void tst_QStateMachine::stopInEventTest() QVERIFY(machine.configuration().contains(s1)); } +void tst_QStateMachine::initialStateIsEnteredBeforeStartedEmitted() +{ + QStateMachine machine; + QState *s1 = new QState(&machine); + machine.setInitialState(s1); + QFinalState *s2 = new QFinalState(&machine); + + // When started() is emitted, s1 should be the active state, and this + // transition should trigger. + s1->addTransition(&machine, SIGNAL(started()), s2); + + QSignalSpy finishedSpy(&machine, SIGNAL(finished())); + machine.start(); + QTRY_COMPARE(finishedSpy.count(), 1); +} + QTEST_MAIN(tst_QStateMachine) #include "tst_qstatemachine.moc" |