LBarret
LBarret

Reputation: 1123

What's the best way to chain Dialogs in QT?

In my app, I have a project features but it needs a chain of dialogs to work.

At start, the user must either open an existing project or create a new one and when creating a new project, the user must specify a folder.

So there is a first dialog for the choice between new or existing project and another one opens to select a folder in the case of a new project.

Right now, I call the exec_() method on the first one, and do everything inside (creating the second dialog, using it, ect). the direct consequence : it is messy as it uses side effects.

So the question is : It is possible to cleanly chain dialogs in QT ?

Upvotes: 2

Views: 178

Answers (2)

Wing Poon
Wing Poon

Reputation: 26

Sounds to me like "state machine" is your friend.

http://www.drdobbs.com/cpp/state-machine-design-in-c/184401236 https://en.wikipedia.org/wiki/Automata-based_programming

  1. In your case, you'd start your state machine from an initial state that runs dialog 1.
  2. You run dialog 1, and when it returns from exec(), determine and update your machine to a new state.
  3. Then run the appropriate dialog for the new state. And so on, until you get to a state that is the end of your dialog chain.

This allows you to have the flexibility in your dialog chain where the next dialog is conditional to what the user selects in the previous dialog, while keeping the logic of the states outside of the dialogs and in a central location.

It's basically a switch statement in a while loop, but a very useful one for managing non-linear / conditional flow in your program.

Hope this helps.

Upvotes: 1

Leo Chapiro
Leo Chapiro

Reputation: 13984

Take a look at QWizard clas:

A wizard (also called an assistant on Mac OS X) is a special type of input dialog that consists of a sequence of pages. A wizard's purpose is to guide the user through a process step by step. Wizards are useful for complex or infrequent tasks that users may find difficult to learn.

Upvotes: 6

Related Questions