How to determine if signal is already connected?
-
@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?
-