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. How to determine if signal is already connected?
Forum Updated to NodeBB v4.3 + New Features

How to determine if signal is already connected?

Scheduled Pinned Locked Moved Unsolved General and Desktop
20 Posts 6 Posters 12.3k Views 2 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.
  • S SPlatten
    20 Jul 2021, 09:45

    @J-Hilk , that's pretty much what I do already, however what I want to do is:

    1. Does "valueChanged" connection exist for spinner widget?
    2. No, connect signal
    J Offline
    J Offline
    J.Hilk
    Moderators
    wrote on 20 Jul 2021, 09:55 last edited by
    #7

    @SPlatten can you give a bit more information/code sections?

    does the check Does "valueChanged" connection exist for spinner widget? happen often, or only after creation of the spinner widget?


    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


    Q: What's that?
    A: It's blue light.
    Q: What does it do?
    A: It turns blue.

    S 1 Reply Last reply 20 Jul 2021, 10:03
    0
    • J J.Hilk
      20 Jul 2021, 09:55

      @SPlatten can you give a bit more information/code sections?

      does the check Does "valueChanged" connection exist for spinner widget? happen often, or only after creation of the spinner widget?

      S Offline
      S Offline
      SPlatten
      wrote on 20 Jul 2021, 10:03 last edited by SPlatten
      #8

      @J-Hilk , the Widget is actually QSpinBox and yes it comes up as soon as I type QSpinBox::, not sure if I misunderstood you, I have two instances of the same widget on a display that shave the result of the spinner, its the constructor of this widget that connects the signals.

      Kind Regards,
      Sy

      J 1 Reply Last reply 20 Jul 2021, 10:14
      0
      • S SPlatten
        20 Jul 2021, 10:03

        @J-Hilk , the Widget is actually QSpinBox and yes it comes up as soon as I type QSpinBox::, not sure if I misunderstood you, I have two instances of the same widget on a display that shave the result of the spinner, its the constructor of this widget that connects the signals.

        J Offline
        J Offline
        J.Hilk
        Moderators
        wrote on 20 Jul 2021, 10:14 last edited by
        #9

        @SPlatten said in How to determine if signal is already connected?:

        its the constructor of this widget that connects the signals.

        well, if you do your connects in the constructor of the widget, than you shouldn't come into the situation, where the valueChanged signal is not connected, right ?


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        S 1 Reply Last reply 20 Jul 2021, 10:33
        0
        • J J.Hilk
          20 Jul 2021, 10:14

          @SPlatten said in How to determine if signal is already connected?:

          its the constructor of this widget that connects the signals.

          well, if you do your connects in the constructor of the widget, than you shouldn't come into the situation, where the valueChanged signal is not connected, right ?

          S Offline
          S Offline
          SPlatten
          wrote on 20 Jul 2021, 10:33 last edited by
          #10

          @J-Hilk , perhaps I haven't made myself clear, I have two widgets that share spinners and a slider, in the constructor of the same two widgets I want to check if the spinners and slider have already had a signal connected, if the answer is no then I want to go ahead with the connection.

          Kind Regards,
          Sy

          P 1 Reply Last reply 20 Jul 2021, 10:37
          0
          • S SPlatten
            20 Jul 2021, 10:33

            @J-Hilk , perhaps I haven't made myself clear, I have two widgets that share spinners and a slider, in the constructor of the same two widgets I want to check if the spinners and slider have already had a signal connected, if the answer is no then I want to go ahead with the connection.

            P Offline
            P Offline
            Pl45m4
            wrote on 20 Jul 2021, 10:37 last edited by
            #11

            @SPlatten said in How to determine if signal is already connected?:

            I have two widgets that share spinners and a slider, in the constructor of the same two widgets I want to check if the spinners and slider have already had a signal connected, if the answer is no then I want to go ahead with the connection.

            But why? You wrote the code. If you haven't connected it already, it's probably not connected :) And if you did, it should stay connected unless you disconnect it manually somewhere, somehow.

            Don't quite unterstand the issue you have here :)


            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 20 Jul 2021, 10:40
            0
            • P Pl45m4
              20 Jul 2021, 10:37

              @SPlatten said in How to determine if signal is already connected?:

              I have two widgets that share spinners and a slider, in the constructor of the same two widgets I want to check if the spinners and slider have already had a signal connected, if the answer is no then I want to go ahead with the connection.

              But why? You wrote the code. If you haven't connected it already, it's probably not connected :) And if you did, it should stay connected unless you disconnect it manually somewhere, somehow.

              Don't quite unterstand the issue you have here :)

              S Offline
              S Offline
              SPlatten
              wrote on 20 Jul 2021, 10:40 last edited by
              #12

              @Pl45m4 , the issue is I have two instances of the same widget, there are three common widgets for setting attributes on instances of the two, in the constructor of the widget I want to automatically check the shared widgets and then only connect if they haven't already been connected.

              The question I am asking is can I detected using the Qt library calls if a signal has already been connected to a widget.

              Kind Regards,
              Sy

              P 1 Reply Last reply 20 Jul 2021, 10:47
              0
              • S SPlatten
                20 Jul 2021, 10:40

                @Pl45m4 , the issue is I have two instances of the same widget, there are three common widgets for setting attributes on instances of the two, in the constructor of the widget I want to automatically check the shared widgets and then only connect if they haven't already been connected.

                The question I am asking is can I detected using the Qt library calls if a signal has already been connected to a widget.

                P Offline
                P Offline
                Pl45m4
                wrote on 20 Jul 2021, 10:47 last edited by
                #13

                @SPlatten

                Besides calling connect again and check its output, there is

                int QObject::receivers(const char *signal)

                • https://doc.qt.io/qt-5/qobject.html#receivers

                Dont know if it's recommended to use...

                Warning: This function violates the object-oriented principle of modularity. However, it might be useful when you need to perform expensive initialization only if something is connected to a signal.

                I guess not, but maybe it helps :)


                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 20 Jul 2021, 10:50
                1
                • P Pl45m4
                  20 Jul 2021, 10:47

                  @SPlatten

                  Besides calling connect again and check its output, there is

                  int QObject::receivers(const char *signal)

                  • https://doc.qt.io/qt-5/qobject.html#receivers

                  Dont know if it's recommended to use...

                  Warning: This function violates the object-oriented principle of modularity. However, it might be useful when you need to perform expensive initialization only if something is connected to a signal.

                  I guess not, but maybe it helps :)

                  S Offline
                  S Offline
                  SPlatten
                  wrote on 20 Jul 2021, 10:50 last edited by
                  #14

                  @Pl45m4 , doesn't calling connect just create another connection? Thats where I am now.

                  Kind Regards,
                  Sy

                  J 1 Reply Last reply 20 Jul 2021, 10:59
                  0
                  • S SPlatten
                    20 Jul 2021, 10:50

                    @Pl45m4 , doesn't calling connect just create another connection? Thats where I am now.

                    J Offline
                    J Offline
                    J.Hilk
                    Moderators
                    wrote on 20 Jul 2021, 10:59 last edited by
                    #15

                    @SPlatten
                    @Pl45m4 is on the right track here,

                    you can/should subclass your spinner and create a function,

                    bool isValueChanged(){
                       static const QMetaMethod valueChangedSignal = QMetaMethod::fromSignal(&MyObject::valueChanged);
                    return isSignalConnected(valueChangedSignal);
                    }
                    

                    https://doc.qt.io/qt-5/qobject.html#isSignalConnected


                    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                    Q: What's that?
                    A: It's blue light.
                    Q: What does it do?
                    A: It turns blue.

                    S P 2 Replies Last reply 20 Jul 2021, 11:02
                    0
                    • J J.Hilk
                      20 Jul 2021, 10:59

                      @SPlatten
                      @Pl45m4 is on the right track here,

                      you can/should subclass your spinner and create a function,

                      bool isValueChanged(){
                         static const QMetaMethod valueChangedSignal = QMetaMethod::fromSignal(&MyObject::valueChanged);
                      return isSignalConnected(valueChangedSignal);
                      }
                      

                      https://doc.qt.io/qt-5/qobject.html#isSignalConnected

                      S Offline
                      S Offline
                      SPlatten
                      wrote on 20 Jul 2021, 11:02 last edited by
                      #16

                      @J-Hilk , thank you, penny has dropped, I see what I have to do now.

                      Kind Regards,
                      Sy

                      1 Reply Last reply
                      0
                      • J J.Hilk
                        20 Jul 2021, 10:59

                        @SPlatten
                        @Pl45m4 is on the right track here,

                        you can/should subclass your spinner and create a function,

                        bool isValueChanged(){
                           static const QMetaMethod valueChangedSignal = QMetaMethod::fromSignal(&MyObject::valueChanged);
                        return isSignalConnected(valueChangedSignal);
                        }
                        

                        https://doc.qt.io/qt-5/qobject.html#isSignalConnected

                        P Offline
                        P Offline
                        Pl45m4
                        wrote on 20 Jul 2021, 11:10 last edited by Pl45m4
                        #17

                        @J-Hilk

                        lol, found receivers() and sender() but not isSignalConnected().

                        Sometimes it's hard to find something, if you don't know what you are looking for :D
                        (function names)


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

                        ~E. W. Dijkstra

                        1 Reply Last reply
                        2
                        • A Offline
                          A Offline
                          aleksejs
                          wrote on 10 Aug 2023, 13:43 last edited by aleksejs 8 Oct 2023, 13:45
                          #18

                          I'm working with Qt not so long, but I see how cumbersome is signal-slot mechanism in comparison to Borland Event-Handler mechanism already.
                          In Borland you write

                          button->OnClick = buttonClickHandler;
                          

                          or

                          if( !button->OnClick )
                              button->OnClick = buttonClickHandler;
                          

                          Until now I haven't seen better Event mechanism than Borland's.

                          JonBJ 1 Reply Last reply 10 Aug 2023, 16:51
                          0
                          • A aleksejs
                            10 Aug 2023, 13:43

                            I'm working with Qt not so long, but I see how cumbersome is signal-slot mechanism in comparison to Borland Event-Handler mechanism already.
                            In Borland you write

                            button->OnClick = buttonClickHandler;
                            

                            or

                            if( !button->OnClick )
                                button->OnClick = buttonClickHandler;
                            

                            Until now I haven't seen better Event mechanism than Borland's.

                            JonBJ Online
                            JonBJ Online
                            JonB
                            wrote on 10 Aug 2023, 16:51 last edited by
                            #19

                            @aleksejs
                            How did that work/what did you specify when buttonClickHandler is a method in a class?

                            Christian EhrlicherC 1 Reply Last reply 10 Aug 2023, 16:56
                            0
                            • JonBJ JonB
                              10 Aug 2023, 16:51

                              @aleksejs
                              How did that work/what did you specify when buttonClickHandler is a method in a class?

                              Christian EhrlicherC Offline
                              Christian EhrlicherC Offline
                              Christian Ehrlicher
                              Lifetime Qt Champion
                              wrote on 10 Aug 2023, 16:56 last edited by Christian Ehrlicher 8 Oct 2023, 17:07
                              #20

                              ... Or if two distinct functions should be called where none is aware of the other?

                              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
                              • W wasawi2 referenced this topic on 9 May 2024, 14:33

                              • Login

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