PDA

View Full Version : QState machine using multiple QThreads



PeterWurmsdobler
14th May 2012, 10:55
Hello,

in my application I have several worker threads managed directly by several context classes, one for every task I want the system to perform. However, I would prefer to organise the threads into a state machine.

Imagine I have a loader thread and a processing thread (with a connection between that loader's signal dataAvailable() to the processor's process() slot. I would like to start the procedure somewhat in this way:

1. in some idle state, accept startTask1(parameter1, parameter2)
2. start processing thread (parameter1)
3. if processing thread is running, start loader thread (parameter2), else go back to idle
4. if loader thread is running, everything is fine and we are in running task1. Here accept stop.
Also only in this state the loader's signal dataAvailable should be forwarded to the processor's process slot.
5. if asked to stop, stop loading thread and tell processor to finish off processing data already loaded
6. once processor thread has finished, emit finished and go back to idle

Would I need to construct objects derived from QState with getters/setters for the parameters and pointers to the threads? Where do I need to start the threads? Perhaps in onEntry()?

I have so far implemented state machines in different languages, but never using QState and friends. Looking into different I still don't quite know how to go about it. Perhaps somebody can help me here.

Kind regards,
peter