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. Sending multiple signals at once

Sending multiple signals at once

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 6 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.
  • S Offline
    S Offline
    shreya_agrawal
    wrote on 23 Feb 2024, 13:06 last edited by
    #1

    I have a left widget and a right widget in my mainWindow. I am populating the left widget with some push buttons(say valves) in a grid layout. When I press the clean button with value 5, I want 5 valves to be clicked simultaneously and turn green. I also want the functionality that the valves should turn green when clicked individually. For this, I have a onValveClicked() slot in valve.cpp. This function just turn the valves green. So, I think I would need to send 5 signals simultaneously so that all those 5 valves turn green at the same time. Can someone tell me if this approach is plausible and correct?

    C A 2 Replies Last reply 23 Feb 2024, 13:11
    0
    • S shreya_agrawal
      23 Feb 2024, 13:06

      I have a left widget and a right widget in my mainWindow. I am populating the left widget with some push buttons(say valves) in a grid layout. When I press the clean button with value 5, I want 5 valves to be clicked simultaneously and turn green. I also want the functionality that the valves should turn green when clicked individually. For this, I have a onValveClicked() slot in valve.cpp. This function just turn the valves green. So, I think I would need to send 5 signals simultaneously so that all those 5 valves turn green at the same time. Can someone tell me if this approach is plausible and correct?

      C Online
      C Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 23 Feb 2024, 13:11 last edited by
      #2

      What's the actual problem then? Simply emit those five signals and connect them to the appropriate slot(s) to change the color.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      S 1 Reply Last reply 23 Feb 2024, 17:02
      1
      • C Christian Ehrlicher
        23 Feb 2024, 13:11

        What's the actual problem then? Simply emit those five signals and connect them to the appropriate slot(s) to change the color.

        S Offline
        S Offline
        shreya_agrawal
        wrote on 23 Feb 2024, 17:02 last edited by
        #3

        @Christian-Ehrlicher
        Thank you for your response!
        I was giving 5 as a reference. Consider for example, if there are 70 valves and I am giving an input 5, then 1-5 valves will be clicked and will turn green, then 6-10 will be clicked and so on. So, I just needed to know if giving multiple signals at once is possible, because 1-5 have to be clicked at the same time. Or is there any other approach possible?

        C J 2 Replies Last reply 23 Feb 2024, 17:17
        0
        • S shreya_agrawal
          23 Feb 2024, 17:02

          @Christian-Ehrlicher
          Thank you for your response!
          I was giving 5 as a reference. Consider for example, if there are 70 valves and I am giving an input 5, then 1-5 valves will be clicked and will turn green, then 6-10 will be clicked and so on. So, I just needed to know if giving multiple signals at once is possible, because 1-5 have to be clicked at the same time. Or is there any other approach possible?

          C Online
          C Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 23 Feb 2024, 17:17 last edited by
          #4

          @shreya_agrawal said in Sending multiple signals at once:

          because 1-5 have to be clicked at the same time.

          What does 'at the same time' means?

          I don't see any problem here - just emit the signals and properly connect them to the slots - what else do you want to do?

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          0
          • S shreya_agrawal
            23 Feb 2024, 17:02

            @Christian-Ehrlicher
            Thank you for your response!
            I was giving 5 as a reference. Consider for example, if there are 70 valves and I am giving an input 5, then 1-5 valves will be clicked and will turn green, then 6-10 will be clicked and so on. So, I just needed to know if giving multiple signals at once is possible, because 1-5 have to be clicked at the same time. Or is there any other approach possible?

            J Offline
            J Offline
            JonB
            wrote on 23 Feb 2024, 17:25 last edited by JonB
            #5

            @shreya_agrawal
            Nothing is really going to happen "at once". Each signal emitted waits for all attached slots to complete, next signal cannot be emitted till them. (At least in default, nonqueued-mode, assuming you are not emitting across threads.)

            Depending on how efficient you wish to be. And depending on whether you you really need to fire the individual buttons' signals or whether you just need to turn them green. You could emit your own signal, with whatever parameters, and have a single slot attached to that. That slot could call the click() signal on each button: that still fires each button's signal in turn, but it saves the outside world having to access and do so on each one. You can write all your logic in this slot, for handling multiple buttons etc. So the outside world only has to emit one signal you define, perhaps with a parameter.

            If you do not need to execute whatever slots would normally fire on each button being clicked but only "turn them green", you could call whatever you do for that directly if you don't need to go via click() slot/clicked() signal.

            S 1 Reply Last reply 24 Feb 2024, 04:41
            1
            • S shreya_agrawal
              23 Feb 2024, 13:06

              I have a left widget and a right widget in my mainWindow. I am populating the left widget with some push buttons(say valves) in a grid layout. When I press the clean button with value 5, I want 5 valves to be clicked simultaneously and turn green. I also want the functionality that the valves should turn green when clicked individually. For this, I have a onValveClicked() slot in valve.cpp. This function just turn the valves green. So, I think I would need to send 5 signals simultaneously so that all those 5 valves turn green at the same time. Can someone tell me if this approach is plausible and correct?

              A Offline
              A Offline
              Agron
              wrote on 24 Feb 2024, 02:50 last edited by Agron
              #6

              @shreya_agrawal
              Yes. Put the valve objects in a vector and then connect signals and slots.

              I am typing on a phone, sorry.

              for( int i=0; ... to 70)
              {
              connect(cleanButton, QPushButton::click,
               vector_of_valve_pointers[i], valveClass::turnGreen)
              
              }
              
              
              

              Like this you make the connection when the clean pushbutton is created.

              You can also dynamically establish connection and terminate them because for each new connection you get an id. So, when a valve doesn't need to be cleaned, you destroy the connection. Or, instead of having a for loop of 70 steps, I'd rather make a new connection as soon as a valve becomes dirty.

              1 Reply Last reply
              0
              • J JonB
                23 Feb 2024, 17:25

                @shreya_agrawal
                Nothing is really going to happen "at once". Each signal emitted waits for all attached slots to complete, next signal cannot be emitted till them. (At least in default, nonqueued-mode, assuming you are not emitting across threads.)

                Depending on how efficient you wish to be. And depending on whether you you really need to fire the individual buttons' signals or whether you just need to turn them green. You could emit your own signal, with whatever parameters, and have a single slot attached to that. That slot could call the click() signal on each button: that still fires each button's signal in turn, but it saves the outside world having to access and do so on each one. You can write all your logic in this slot, for handling multiple buttons etc. So the outside world only has to emit one signal you define, perhaps with a parameter.

                If you do not need to execute whatever slots would normally fire on each button being clicked but only "turn them green", you could call whatever you do for that directly if you don't need to go via click() slot/clicked() signal.

                S Offline
                S Offline
                shreya_agrawal
                wrote on 24 Feb 2024, 04:41 last edited by
                #7

                @JonB
                By the approach you mentioned, I can turn multiple valves green at the same time, but I also want to click them simultaneously, while turning them green. If I pass the clicked() signal in a loop in my turnGreen slot, then this signal will go individually for each valve. But I want all those valves to be clicked at once. Because all those signals have to go to the PLC at once, so that those valves can be cleaned. I hope I am able to clearly put forward my use case.

                C P 2 Replies Last reply 24 Feb 2024, 07:27
                0
                • S shreya_agrawal
                  24 Feb 2024, 04:41

                  @JonB
                  By the approach you mentioned, I can turn multiple valves green at the same time, but I also want to click them simultaneously, while turning them green. If I pass the clicked() signal in a loop in my turnGreen slot, then this signal will go individually for each valve. But I want all those valves to be clicked at once. Because all those signals have to go to the PLC at once, so that those valves can be cleaned. I hope I am able to clearly put forward my use case.

                  C Online
                  C Online
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on 24 Feb 2024, 07:27 last edited by
                  #8

                  There is nothing like 'at once' - it's done one after the other. When you want to pass a state to something else then you have to accumulate the result (= wait some time). This is nothing Qt specific here and for sure has nothing to do with signals and slots.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  1 Reply Last reply
                  2
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 24 Feb 2024, 08:30 last edited by
                    #9

                    Hi,

                    Then you are tying too much of the business logic to your UI.

                    Taking the GUI aside, how would you send the command to your PLCs so they start doing their stuff at the same time ?

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    1
                    • S shreya_agrawal
                      24 Feb 2024, 04:41

                      @JonB
                      By the approach you mentioned, I can turn multiple valves green at the same time, but I also want to click them simultaneously, while turning them green. If I pass the clicked() signal in a loop in my turnGreen slot, then this signal will go individually for each valve. But I want all those valves to be clicked at once. Because all those signals have to go to the PLC at once, so that those valves can be cleaned. I hope I am able to clearly put forward my use case.

                      P Offline
                      P Offline
                      Pl45m4
                      wrote on 24 Feb 2024, 10:32 last edited by Pl45m4
                      #10

                      @shreya_agrawal

                      By the way: Since you are talking about "at once".
                      If the only thing you do is turning your valve buttons green and do some other "cheap" tasks, the human eye wont see any difference if this happens really "at once" (litterally same time) or some milisecs apart when signals are processed sequentially


                      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                      ~E. W. Dijkstra

                      S 1 Reply Last reply 26 Feb 2024, 05:00
                      0
                      • P Pl45m4
                        24 Feb 2024, 10:32

                        @shreya_agrawal

                        By the way: Since you are talking about "at once".
                        If the only thing you do is turning your valve buttons green and do some other "cheap" tasks, the human eye wont see any difference if this happens really "at once" (litterally same time) or some milisecs apart when signals are processed sequentially

                        S Offline
                        S Offline
                        shreya_agrawal
                        wrote on 26 Feb 2024, 05:00 last edited by
                        #11

                        @Pl45m4
                        Thank you for your response !
                        Yes, I tried passing the signals in the for loop and its actually not visible to the naked eye, so I will go forward with that method.

                        1 Reply Last reply
                        0
                        • S shreya_agrawal has marked this topic as solved on 26 Feb 2024, 05:00

                        4/11

                        23 Feb 2024, 17:17

                        topic:navigator.unread, 7
                        • Login

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