[Qt-interest] QStateMachine: Jumping to a specific state

Mandeep Sandhu mandeepsandhu.chd at gmail.com
Fri Apr 9 13:27:46 CEST 2010


On Fri, Apr 9, 2010 at 3:20 PM, Paul Drummond <paul.drummond at iode.co.uk> wrote:
> Let me explain my app a bit more.
>
> I have an app that I want to write in QML but need to use C++ because QML
> won't be released in time!  I only mention this because states/transitions
> are more prominent in QML and that's the mindset I am in for developing this
> app.  I have based the app loosely on the hyperui demo code but it doesn't
> use "pages" as such so I've changed it quite a bit.
>
> The app has 3 main "pages" where each page transition is represented by a
> state.  Generally the user moves from page1 to page2 to page3 via states and

Why are you representing a transition from 1 page to other as a state?
Keep the _pages_ as states and moving from 1 page to another as a
transition.

> this works fine.
>
> There is also a button bar at the bottom of the screen that provides a
> button short-cut so the user can go back to page1 from any page.  Ideally, I
> would like to implement this button to say "setState(page1)" but there is no
> api for that as far as I know.

This can be easily done by creating a new transition, say "shortcut"
transition (more specifically create a SignalTransition). For this
transition set the target state as S1 (which say represents page 1).
Now add this shortcut transition to each state from which you want to
transition.

BUT, this would be against the hierarchical state machine principle.
So, put all the 3 states (representing the pages) as children of a new
super state group called, say "Shortcut State" group.

Now add the shortcut transition (mentioned above) to this super group.
This essentially means that when in either states S1, S2 or S3, if the
"top" button is clicked, transition to state S1.

I guess this is what you want?

HTH,
-mandeep

>
> In C++, it feels like I am try to use state machines where I need something
> more dynamic but I am coming from QML where states and transitions are the
> norm so I thought I might just be missing something?
>
> Paul Drummond
>
> _______________________________________________
> 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