Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Navigation between forms
Forum Update on Monday, May 27th 2025

Navigation between forms

Scheduled Pinned Locked Moved Solved General and Desktop
dialogslogin
4 Posts 3 Posters 1.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 81058 Offline
    81058 Offline
    8105
    wrote on last edited by 8105
    #1

    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.

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      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

      connect(log,SIGNAL(success()),mW,SLOT(show());

      if something fails.
      connect(log,SIGNAL(Fail()),mW,SLOT(hide());

      So tight coupling between Login object & MainWindow should be avoided.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      6
      • M Offline
        M Offline
        mostefa
        wrote on last edited by
        #3

        Hi @8105

        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:

        http://doc.qt.io/qt-5/qstackedwidget.html#details

        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:

        http://doc.qt.io/qt-4.8/statemachine-api.html

        In Qt examples there is still an example with using QStackedWidget

        http://doc.qt.io/qt-5/qtwidgets-dialogs-configdialog-example.html

        Hope this can help !

        1 Reply Last reply
        2
        • 81058 Offline
          81058 Offline
          8105
          wrote on last edited by
          #4

          Thank you both for the advice.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved