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
Forum Updated to NodeBB v4.3 + New Features

Using signal and slots to send data to another window

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 875 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 14 Apr 2022, 03:57 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.

    J 1 Reply Last reply 14 Apr 2022, 06:14
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on 14 Apr 2022, 04:23 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 14 Apr 2022, 09:38
      0
      • B burrito1111
        14 Apr 2022, 03:57

        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.

        J Offline
        J Offline
        JonB
        wrote on 14 Apr 2022, 06:14 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
          14 Apr 2022, 04:23

          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 14 Apr 2022, 09:38 last edited by
          #4

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

          J J 2 Replies Last reply 14 Apr 2022, 11:19
          0
          • B burrito1111
            14 Apr 2022, 09:38

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

            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 14 Apr 2022, 11:19 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
              14 Apr 2022, 09:38

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

              J Offline
              J Offline
              JonB
              wrote on 14 Apr 2022, 11:21 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

              1/6

              14 Apr 2022, 03:57

              • Login

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