[Qt-interest] unable to use more than 1 transition added to a state (QT StateMachine Framework)

Sean Harmer sean.harmer at maps-technology.com
Thu Mar 18 14:01:08 CET 2010


Hi,

On Thursday 18 March 2010 12:47:46 Mandeep Sandhu wrote:
> On Thu, Mar 18, 2010 at 5:35 PM, Sean Harmer
> 
> <sean.harmer at maps-technology.com> wrote:
> > This way you can "override" the behaviour that a child state inherits
> > from its parent. All you need to do is to provide a pointer to the s0
> > state to this specialised transition class when you create it so that it
> > knows what to check.
> 
> But this hardcodes the state s0 in its transition check...I guess I
> can take the state to skip as a param to the constructor and use it in
> the eventTest....

Only in this very simple example. As you say you can abstract this out, but 
only you have the knowledge of your SM's requirements to be able to tell if 
this makes sense to abstract it out so as to be re-usable with other states.

For example, in other cases you may need to check that the SM is not in either 
of 1 or more child states. In this case it would be worth making your guarded 
transition class check that the SM is not in any state of a list of supplied 
child states. This way you could reuse it for many such situations. In other 
cases you may need to check more complicated combinations of states, this 
would then require another specialised class that inherits from 
QAbstractTransition.

It is down to you to decide the best way to abstract the commonality between 
such guarded transitions into a reasonable set of transition classes. We have 
some pretty complex SMs that we use to control hardware with many 
interdependent subsystems and we have found it necessary to write a handful of 
specialised guarded transitions. It is not an onerous task since you only have 
to override one or two functions and it brings a great deal of power with it.

> Or should the HSM be constructed in a different way so that such hacks
> are not needed?

It is not a hack, this is a legitimate way of implementing guarded 
transitions. If it still feels like a hack then you should examine the 
possibility of refactoring your SM structure. But only you have the domain-
specific knowledge to do so in your particular case.

Cheers,

Sean



More information about the Qt-interest-old mailing list