Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
6.7.1
-
None
Description
The following program attempts to create a QStateMachine that runs two child state machines in parallel.
While the two child state machines are run and finish, the parent state s1 never emits the QState::finished signal when they have finished, and so the parent state machine can't progress.
#include <QCoreApplication> #include <QStateMachine> #include <QState> #include <QFinalState> #include <QAbstractTransition> #include <QSignalTransition> QStateMachine *createChildFSM(QCoreApplication& a, QState *parent) { QStateMachine *fsm = new QStateMachine(parent); QState *s1 = new QState(); QFinalState *s2 = new QFinalState(); fsm->addState(s1); fsm->addState(s2); fsm->setInitialState(s1); s1->addTransition(s2); a.connect(s1, &QState::entered, []() \{qDebug() << "Child state 1 entered";}); a.connect(s2, &QState::entered, []() \{qDebug() << "Child state 2 entered";}); a.connect(fsm, &QStateMachine::finished, []() \{qDebug() << "Child finished";}); return fsm; } int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QStateMachine *fsm = new QStateMachine(); QState *s1 = new QState(QState::ParallelStates); QFinalState *s2 = new QFinalState(); fsm->addState(s1); fsm->addState(s2); fsm->setInitialState(s1); s1->addTransition(s1, &QState::finished, s2); createChildFSM(a, s1); createChildFSM(a, s1); a.connect(s1, &QState::entered, []() \{qDebug() << "Parent state 1 entered";}); a.connect(s2, &QState::entered, []() \{qDebug() << "Parent state 2 entered";}); a.connect(s1, &QState::finished, []() \{qDebug() << "Parent state 1 finished";}); a.connect(fsm, &QStateMachine::finished, []() \{ qDebug() << "Parent finished"; }); a.connect(fsm, &QStateMachine::finished, fsm, &QStateMachine::deleteLater); a.connect(fsm, &QStateMachine::finished, qApp, &QCoreApplication::quit); fsm->start(); return a.exec(); }
The program only outputs:
Parent state 1 entered Child state 1 entered Child state 2 entered Child finished Child state 1 entered Child state 2 entered Child finished
If I remove one of the child state machines, then the QState::finished signal is emitted, and the parent state finishes.
https://doc.qt.io/qt-6/qtstatemachine-cpp-guide.html says:
"For parallel state groups, the QState::finished() signal is emitted when all the child states have entered final states."
Attachments
Gerrit Reviews
For Gerrit Dashboard: QTBUG-126419 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
617577,9 | Emit QState::finished if parallel QStateMachine states are finished | dev | qt/qtscxml | Status: NEW | +1 | +1 |