views:

48

answers:

1

Dear All, I'm going crazy with QStateMachine wth ParallelState. I've a main state (sequential) which contain a first state, a second state which contains a group of parallel states, and another state that is again sequential. The first state represent a process which create N input files, the second represents N threads which works over each input (one thread for one file) and the last state represents a process which generates a report of the overall process (need to wait that second state has completely finished). Well, the problem is just when I need to create a barrier between the second state and the third one. I need some barrier in order to complete all the threads and I'm not able to do it. Following documentation it is said that the composite state which is parallel, call finished when all its children enter in the final state. First of all what does it mean in this case, entering in a final state? May I need to create a final state for each state inside my parallel state? Anyway I try this but nothing. The result is that when the first thread finishes, the final state of my container is called.

This is a snippet:

QState *mainState = new QState(QState::ExclusiveStates);

// Create the first state associated to the first process
QState *firstState = new QState(mainState);
QObject::connect(firstState, SIGNAL(entered()), this, SLOT(executeFirstProcess()));

// parallel container state
QState *parallelContainerState = new QState(QState::ParallelStates, mainState);
firstState->addTransition(this, SIGNAL(goToNextStep()), parallelContainerState);

QFinalState *parallelFinalState = new QFinalState(parallelContainerState);

int parallelStepCounter = 0;
for(;parallelStepCounter < 5; parallelStepCounter++) {
    QState *pState = new QState(parallelContainerState);
    QObject::connect(pState, SIGNAL(entered()), this, SLOT(executePState()));
    pState->addTransition(pState, SIGNAL(finished()), parallelFinalState);
}

QState *reportState = new QState(mainState);
QObject::connect(reportState, SIGNAL(entered()), this, SLOT(generateReport()));
parallelContainerState->addTransition(parallelContainerState, SIGNAL(finished()), reportState);

... set initial state, start machine bla bla...

How can wait that second state has completely finished? I also try to use QObject::connect with finished signal of each pState, but it is not called.

thank you, best

A: 

The Qt documentation states that:

For parallel state groups, the QState::finished() signal is emitted when all the child states have entered final states.

This leads me to believe that rather than having a QFinalState connected to parallelContainerState, instead connect all child states to final states of their own.

Fredrik H