Best way make this sequence based to user choice

  • Hi all
    In my app develop using QML I need to start a sequence of steps based to user choice. For example create a new document. At first check for current one is modified, in case of yes ask to user if he want to save. If yes open file save dialog and check if the name document name inserted already exist. If yes ask if overrite. If yes overrtie and return to first step where new document is created. If no return to previous step for ask of a new file document name (and so on). This is one of tha classic sequence. Now make this steps using Qt C++ is very easy since for each step a modal messagebox stop the execution of the code waiting for user choice. However, since QML is all asyncronous is not possible to stop the executon in a specific point waitint for a reply than code for make this sequence can become really complex and redundant.
    What is the bast way to make this sequence in QML in an easy way? (if exist...)
    Thank you

  • @Suppaman I did some complex dialog sequences with StateMachine. I needed to take account of TCP connection to another device which had to be established if not ready already, success and failure of the connection at any moment, end user cancelling or accepting the action etc. It works when you learn how to use StateMachine. Was it easy? No. Was it the best way? I don't know. I migrated to StateMachine in an early phase because sequential actions didn't seem to be enough for the needs, so I don't even know if it had been possible without state machine. But in the end it might be easier to use StateMachine than to make one change after another to an ad hoc sequential code. A state machine will be robust if you design the states properly and after you have learned how to use and implement a state machine. Until that it will be painful.

  • @Eeli-K thank you for your contribute. I came to the same conclusion about use of StateMachine too and I was making some experiment with it. It can work but the doubt I have is how to "manage" the switch back to the previous state from last state once user make a choice. I mean, following my example if the user select to don't overrite the existing file document the state machine have to move back to the previous state of the sequence where it again ask the name of the file document to save. On the contrary if the user decide to overrite the document the state machine have to move back the the first state of the sequence (where new document is created).
    How did you manage this "stack" of states?

  • @Suppaman It's been a long time since I made it, I don't remember everything. But it should be possible with normal means. Mostly it's that onEntered of a state makes changes to the visible state of a dialog, including opening and closing it, and SignalTransition receives signals from dialogs or when the user does something. If you can write a self-contained minimal example with the problem identified I could look at it further.

Log in to reply