Navigation between forms
Good evening everyone.
I'd like some advice about the design of my little Qt app. But first here's what in my app at the moment:
1- my MainWindow is pretty much your typical menu, multiple buttons dedicated each for a certain functionality (login, help, about, etc...)
2- every functionality has a designer form class.
3- currently, main creates an instance of MainWindow and shows it
Now, what I know how to do is creating instances of the design forms and showing them in a "MainWindow()::on_functionality_button_clicked()" slot, and hiding the MainWindow.
The problem with that is that if I chose to login for example, the login form is showed and if I successfully identify myself, I can use the same mechanism to, say, open an interface or something.
But what if I want to cancel the login, and want to view the user guide before? If the login form is instantiated inside a slot in MainWindow, how can I reshow the MainWindow if I close a form functionality like the login?
How can I navigate between forms in a responsive way?
I hope you're understanding my problem. Your help is really appreciated.
Your loginObject & MainWindow object should be independent. Each of these objects should have appropriate signals and slots. You need to connect between them using signal & slots.
Login object has to have success & fail signals.
Login *log = new Login
MainWindow *mW = new MainWindow
if something fails.
So tight coupling between Login object & MainWindow should be avoided.
If you have a lot of widgets and you want to navigate between these widgets for me the best solution to do , is to have a QStackedWidget and add all your pages to this stackedWidget
The QStackedWidget class provides a stack of widgets where only one widget is visible at a time.
Have a look at QStackedWidget doc:
As second thing i advise you to use is the QStateMachine framework, this will allow you to know at any moment (the state of your app , and the form) and to go to the current next state (form)
Have a look at QStatemachine framework:
In Qt examples there is still an example with using QStackedWidget
Hope this can help !
Thank you both for the advice.