How to determine if signal is already connected?
-
@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.
-
@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 ?
-
@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.
-
@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 :)
-
@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.
-
Besides calling
connect
again and check its output, there isint QObject::receivers(const char *signal)
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 :)
-
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 writebutton->OnClick = buttonClickHandler;
or
if( !button->OnClick ) button->OnClick = buttonClickHandler;
Until now I haven't seen better Event mechanism than Borland's.
-
... Or if two distinct functions should be called where none is aware of the other?
-