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. Using signal and slots to send data to another window
Qt 6.11 is out! See what's new in the release blog

Using signal and slots to send data to another window

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 1.1k 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.
  • B Offline
    B Offline
    burrito1111
    wrote on last edited by
    #1

    Hi. I am currently working on a small QT project for my university project. Now, I just need to send a signal to another window from the current window. Basically, I need to send the "username" as a QString to another window every time I press the "login" button in my login window. Would it be possible to do that?

    I know it has something to do with Signals and Slots, but I couldn't do it myself since I am not familiar with the syntax. Appreciate the help.

    JonBJ 1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by ChrisW67
      #2

      Yes it is possible.

      Are the two on-screen windows part of the same program (process), or are they separate programs (processes)?

      B 1 Reply Last reply
      0
      • B burrito1111

        Hi. I am currently working on a small QT project for my university project. Now, I just need to send a signal to another window from the current window. Basically, I need to send the "username" as a QString to another window every time I press the "login" button in my login window. Would it be possible to do that?

        I know it has something to do with Signals and Slots, but I couldn't do it myself since I am not familiar with the syntax. Appreciate the help.

        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by
        #3

        @burrito1111
        Although it is possible to do this with signals & slots, the more usual way would not. It would just have a a QDialog for the "login window", with TextEdits for username & password, and an "OK"/"Login" button. The dialog would be run as "modal" via QDialog::exec(). When it exits via the user pressing "OK", the "calling" code would just access the username/password from the dialog instance (provide methods for that).

        1 Reply Last reply
        1
        • C ChrisW67

          Yes it is possible.

          Are the two on-screen windows part of the same program (process), or are they separate programs (processes)?

          B Offline
          B Offline
          burrito1111
          wrote on last edited by
          #4

          @ChrisW67 theyre part of the same project. two main windows.

          jsulmJ JonBJ 2 Replies Last reply
          0
          • B burrito1111

            @ChrisW67 theyre part of the same project. two main windows.

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @burrito1111 said in Using signal and slots to send data to another window:

            theyre part of the same project. two main windows

            So, same process with two main windows?
            Then it is easy: simply connect a signal from one window to a slot in the other.
            See https://doc.qt.io/qt-5/signalsandslots.html
            Something like:

            LoginWindow *logWindow = new LoginWindow();
            connect(logWindow, &LoginWindow::login, this, &MainWindow::doLogin);
            

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • B burrito1111

              @ChrisW67 theyre part of the same project. two main windows.

              JonBJ Online
              JonBJ Online
              JonB
              wrote on last edited by JonB
              #6

              @burrito1111
              In that case since the login window is not a modal dialog you will need to attach a slot to the QPushButton::clicked signal of the login window. You can either subclass so that you can create a new signal which passes the username/password, or you can have the slot in the other window access the username from the login window by it have a public "getter" method to call.

              Incidentally, since your "logon" window is not a modal dialog, what happens/is to stop user from logging on more than once? And how does the receiving window behave before the user has used the other window to login?

              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