Results 1 to 17 of 17

Thread: Chaining multiple UI with QStatemachine

  1. #1
    Join Date
    Feb 2014
    Posts
    10
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Chaining multiple UI with QStatemachine

    Hi,
    I'd like to use a QStatemachine to handle the state of an application. According to the current state of the SM, a different UI should appears like here :

    <QSM states> [Start] -> [State1] -> [State2] ->[State3]->[State4]->etc

    <UI> [Splash screen for 10s] -> [ UI1] -> [UI2] -> [ UI3 ] -> [UI4]


    A button click create the transition between the states.

    Whereas I could use the QStatemachine from Qt docs from a single ui, my problem is I don't see how to implement the relationship when SM changed in the main or MainWidow class to call
    other classes/UI.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Chaining multiple UI with QStatemachine

    Each QState can set properties on objects.

    For example the visible property of a window, or the currentIndex property of a widget stack.

    Cheers,
    _

  3. #3
    Join Date
    Feb 2014
    Posts
    10
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Chaining multiple UI with QStatemachine

    OK but how to access different ui from the same place then ?
    from my example the main (or MainWindow) starts the splash creen ui and then must hide it to call the UI1 [SM transition] ,
    then do the same if the UI1/Btn click event arise[SM transition] : hide UI1 and show UI2, and so on.


    edit : another approach could be to access the SM from the different ui to update the SM itself ?
    Last edited by dlewin; 14th January 2015 at 12:04.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Chaining multiple UI with QStatemachine

    If the main window creates all these UIs then it should be able to pass these pointers to the states' assignProperty() method.

    You can also use a mediator object that has the properties which get changed by the state machine and other parts of the program access that mediator.

    Doesn't really have anything to do with either Qt or QSM, basic C++ at work.

    Cheers,
    _

  5. #5
    Join Date
    Feb 2014
    Posts
    10
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Chaining multiple UI with QStatemachine

    anda_skoa I see what you mean, but the UI are quite specific and are created from the designer, insteead by code.
    Thus, they are not created by the Mainwindow.
    For the same reasons, while being a really interesting idea, the mediator object can't have the different UI assigned to it.

    Cheers

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Chaining multiple UI with QStatemachine

    Quote Originally Posted by dlewin View Post
    anda_skoa I see what you mean, but the UI are quite specific and are created from the designer, insteead by code.
    Doesn't change anything.

    Quote Originally Posted by dlewin View Post
    Thus, they are not created by the Mainwindow.
    They need to be created somewhere.

    Quote Originally Posted by dlewin View Post
    For the same reasons, while being a really interesting idea, the mediator object can't have the different UI assigned to it.
    The mediator approach is the one you use when you don't have access to the UI pointers from where you create the state machine.
    Hence the mediator being accessible from everywhere.

    Cheers,
    _

  7. #7
    Join Date
    Feb 2014
    Posts
    10
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Chaining multiple UI with QStatemachine

    ok, I think I got it :
    * I create a "MediatorWhatever" Class
    * in "MediatorWhatever" I create a QStatemachine + instance of splash screen class
    * from "Splashscreen" Class on time out (10s in my example) I update the SM state
    * in "MediatorWhatever" I create an instance of UI1 class
    * from "UI1" Class on Btn click event I update the SM state
    * and so on ...

    is that what you mean ?

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Chaining multiple UI with QStatemachine

    No, but that would also work.

    If you have a class that has access to all UI, either because it creates all of them or it receives all pointers, then it is a good place to create the state machine.
    If that class is the main window class or a separate class really doesn't matter.

    The mediator approach is something entirely different, just fortget about it

    Cheers,
    _

  9. #9
    Join Date
    Feb 2014
    Posts
    10
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Chaining multiple UI with QStatemachine

    thanks?
    Well ... ok I forget i.

    what I don't see the way is : "it receives all pointers,"

  10. #10
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Chaining multiple UI with QStatemachine

    What does your code look right now?

    How and where do you create the instances of these UIs?

    Cheers,
    _

  11. #11
    Join Date
    Feb 2014
    Posts
    10
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Chaining multiple UI with QStatemachine

    To simplify the explanations I'd say I work by validating function parts, that are :
    * using a QStatemachine :

    Qt Code:
    1. QState *s1 = new QState();
    2. QLabel *label1 = new QLabel("Original state ");
    3. QState *s2 = new QState();
    4. QState *s3 = new QState();
    5.  
    6. s1->assignProperty(&button, "text", "Click me"); //Property is assign only when state-machine is started.
    7.  
    8. machine.addState(s1);
    9. machine.addState(s2);
    10. machine.addState(s3);
    11. machine.setInitialState(s1);
    12.  
    13. // Definition de l'enchainement des états
    14. s1->addTransition(&button, SIGNAL(clicked()), s2);
    15. s2->addTransition(&button, SIGNAL(clicked()), s3);
    16. s3->addTransition(&button, SIGNAL(clicked()), s1);
    17.  
    18. // Definition de l'action des états
    19. s1->assignProperty(label1, "text", "Splash screen");
    20. s2->assignProperty(label1, "text", "1 Menu");
    21. s3->assignProperty(label1, "text", "3 Maintenance");
    22.  
    23. machine.start();
    24.  
    25. layout->addWidget(&button);
    26. layout->addWidget(label1);
    To copy to clipboard, switch view to plain text mode 
    ------------------------------------------------------------

    * I aim to use this code into whatever allows me to do what I want to, like any Qtcreator application wizard will generate :

    I use the main (but not sure this is the best idea) :

    Qt Code:
    1. SplashScreen *SScreen = new SplashScreen ();
    2.  
    3. SScreen ->show();
    To copy to clipboard, switch view to plain text mode 
    then in MainWindow I use :
    Qt Code:
    1. void MainWindow::Splash_Timerout()
    2. {
    3. //this->show();
    4. Frm_Warning_Sourceinvalide *Warning_window = new Frm_Warning_Sourceinvalide();
    5. Warning_window->show();
    6. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by anda_skoa; 16th January 2015 at 12:48. Reason: missing [code] tags

  12. #12
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Chaining multiple UI with QStatemachine

    Some options:

    Qt Code:
    1. s1->assignProperty(splashScreen, "visible", true);
    2. s2->assignProperty(warningWindow, "visible", true);
    3.  
    4. // and a transition that triggers s1 -> s2 when the slash closes/times out.
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. connect(s1, SIGNAL(entered()), someReceiver, SLOT(showSplash()));
    2. connect(s2, SIGNAL(entered()), someReceiver, SLOT(showWarning()));
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  13. #13
    Join Date
    Feb 2014
    Posts
    10
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Chaining multiple UI with QStatemachine

    great indeed this is better.
    Then : I still need to update the S1 transition from MainWindow when it's finished after 10s

  14. #14
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Chaining multiple UI with QStatemachine

    That's what I wrote, no?

    Qt Code:
    1. // and a transition that triggers s1 -> s2 when the slash closes/times out.
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  15. #15
    Join Date
    Feb 2014
    Posts
    10
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Chaining multiple UI with QStatemachine

    I meant : by code.

    Thanks

  16. #16
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Chaining multiple UI with QStatemachine

    I don't understand what you mean.

    Of course adding a transition is done by code, how else would you do it?

    Cheers,
    _

  17. #17
    Join Date
    Feb 2014
    Posts
    10
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Chaining multiple UI with QStatemachine

    It's ok.

    I would paraphrase Magrite elsewhere :

    // and a transition that triggers s1 -> s2 when the slash closes/times out.

    "this is not a code"

Similar Threads

  1. QStateMachine set state
    By matteo.ceruti in forum Qt Programming
    Replies: 1
    Last Post: 22nd October 2012, 08:33
  2. Help using QStateMachine
    By d_stranz in forum Qt Programming
    Replies: 6
    Last Post: 10th October 2011, 08:52
  3. Aid on QStateMachine
    By giorgik in forum Qt Programming
    Replies: 1
    Last Post: 27th April 2010, 11:24
  4. QStateMachine
    By piotr.dobrogost in forum Qt Programming
    Replies: 3
    Last Post: 6th December 2009, 09:17
  5. Chaining QIODevice Instances
    By wswartzendruber in forum Newbie
    Replies: 9
    Last Post: 29th July 2009, 21:23

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.