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. Swap from one ui. Form to another on button click
Forum Updated to NodeBB v4.3 + New Features

Swap from one ui. Form to another on button click

Scheduled Pinned Locked Moved General and Desktop
4 Posts 4 Posters 6.3k Views 1 Watching
  • 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.
  • H Offline
    H Offline
    Hoppo
    wrote on last edited by
    #1

    Hello all,

    I am very new to -QT- Qt Creator and -QT- Qt and c++ in general. I am trying to learn how to develop desktop applications and have encountered a slight problem thats held me up for a while now.

    I want to be able to swap which .ui form is being displayed via the click of a button. What i want to achieve is, having a log in screen and once the user clicks log in they move to the logged in screen. I am going to add database validation of users etc but at the moment i just want to get the swapping of forms working.

    My project layout looks like this

    ->Headers
    -- mainwindow.h

    ->Sources
    -- main.cpp
    --mainwindow.cpp

    ->Forms
    --logged.ui
    --mainwindow.ui

    ->Resources
    --Resources.qrc

    On the applicatin load it displays the mainwindow.ui and i need it to display the logged.ui on the button click. I have created the button and added a Signal, aswell as adding the relevant code into the mainwindow.h file
    @public slots:
    void LoginClicked();@

    In my mainwindow.cpp file i then have

    @void MainWindow::LoginClicked() {

    }@

    I just need to figure out what code goes in that function to change the form thats visible, i.e. hide the mainwindow.ui and show logged.ui

    Many Thanks

    David

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chris H
      wrote on last edited by
      #2

      The way I handle it in my app is to make the login screen a member of the main window: in the main window's constructor I create and show the login screen and hide the main window itself. I also connect the accept() signal from the dialog to a function that validates the input and shows the main window if it checks out. I'm sure there are other ways of handling it, but this was the simplest I could think of.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        miroslav
        wrote on last edited by
        #3

        Switching the UI file itself is not needed in this case. Simply make two separate widgets, and create and show the login window when needed (that is, if the login window is a dialog).

        If the login screen should be in the main window, you can use a QStackedWidget, add both pages, and programmatically switch which one should be shown.

        Mirko Boehm | mirko@kde.org | KDE e.V.
        FSFE Fellow
        Qt Certified Specialist

        1 Reply Last reply
        0
        • A Offline
          A Offline
          amleto
          wrote on last edited by
          #4

          if the login details are ok, send a signal that connects to some slot that creates + shows the logged.ui form, and then hide() the mainwindow

          [code]
          void mainwindow::tryLogin( /* some details */)
          {
          bool login_is_ok = some_checking_method(/details/);
          if (login_is_ok)
          {
          emit signal_do_login();
          hide();
          }
          }
          [/code]

          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