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

Mandeep Sandhu mandeepsandhu.chd at gmail.com
Thu Mar 18 11:16:15 CET 2010


On Thu, Mar 18, 2010 at 3:07 PM, Sean Harmer
<sean.harmer at maps-technology.com> wrote:
> Hi,
>
> On Wednesday 17 March 2010 08:56:01 Mandeep Sandhu wrote:
>> On further debugging this problem I found that the issue is because of
>> attaching the same transition to more than 1 state.
>>
>> Can't a transition be attached to more than 1 state?
>>
>> Eg. If i define my transition as "On event E1, move to State S1"
>>
>> I attach this transition to S3 and S6...now if an event E1 occurs
>> while the state machine is in S3 or S6, it should transition to S1.
>> Correct?
>>
>> Or is this a bug in the state machine framework?
>
> This is not a bug in the SM framework. You need to use multiple instances of
> your specialised guarded transition class. The reason is because each instance

Having multiple instances of my transition for the _same_ event would
again violate the principle of Hierarchical SM's.

I'll illustrate my SM which needed the same transition to be attached
to 2 states:

s0-(e1)->s1-(e2)->s2
         ^        |
         |__(e1)__|

(this dia looks proper with fixed width font!:))

So, on event e1 the SM transitions to s1, whether its in s0 or s2.

To avoid 2 e1 transitions, I can club s0 and s2 in a super-group (sg1)
and apply a single transition for e1 to this super-group. This would
be within the principle of HSM's (there'll also be a transition from
s1 to s2 on e2).

Now, I add another state/transitions to the same SM as below:

s1-(e3)->s3 and s2-(e3)->s3

This (if seen alone) would require another super-group (sg2) which has
s1 and s2 and 1 transition for e3 attached to sg2.

But how do I combine sg1 & 2. Basically s2 exists in both these
groups...While reading Harrel's statecharts its mentioned that
sometimes for overlapping states duplication might be needed.

Any ideas on how this canbe resolved the proper HSM way?

Thanks,
-mandeep


> of your transition class knows about its source and destination states. If you
> add a transition to a state and then add the same instance to another state,
> then its internal source and/or destination state pointers will get
> overwritten with the new ones. Hence there will be no transition between the
> original source and destination states.
>
> Cheers,
>
> Sean
>
>>
>> Thanks,
>> -mandeep
>>
>> On Tue, Mar 16, 2010 at 7:39 PM, Mandeep Sandhu
>>
>> <mandeepsandhu.chd at gmail.com> wrote:
>> > Hi All,
>> >
>> > I'm implementing my FSM which reacts to User QEvents (event type >
>> > QEvent::User). An external app does postEvent(QEvent) to the state
>> > machine.
>> >
>> > As part of that I'm implementing my own custom transition which
>> > extends QtAbstractTransition and reimplements the eventTest() method
>> > as shown here:
>> >
>> > http://doc.qt.nokia.com/4.6/statemachine-api.html#events-transitions-and-
>> > guards
>> >
>> > However, if I add more than one such transition to my state (say to
>> > S3) then the statemachine is unable to find any transition and remains
>> > stuck at S3. I've seen the code in example/eventtransitions where they
>> > add TWO QEventTransition's to a state and it seems to be working fine.
>> > I have set valid target states to these transitions.
>> >
>> > Note that if add only ONE transition, then it works fine, as in on the
>> > correct event I transition to the next state.
>> >
>> > Any clues as howto further debug this issue?
>> >
>> > thanks,
>> > -mandeep
>>
>> _______________________________________________
>> Qt-interest mailing list
>> Qt-interest at trolltech.com
>> http://lists.trolltech.com/mailman/listinfo/qt-interest
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>



More information about the Qt-interest-old mailing list