How to determine if signal is already connected?
-
@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
connectagain 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 :)
-
Besides calling
connectagain 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.
-
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.
-
@aleksejs
How did that work/what did you specify whenbuttonClickHandleris a method in a class?... Or if two distinct functions should be called where none is aware of the other?
-
W wasawi2 referenced this topic on
-
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.
@aleksejs
Borland made it simple and thus easy to use. "Simple" means that 1 signal could have 0 or 1 slot (button->OnClick is the signal, buttonClickHandler is the slot). If one wanted to connect more slots to 1 signal then had to implement handling more slots (listeners) in the 1 connected slot. For a simple GUI 1 slot was enough of course. "Simple" also means that threads were not considered at all, it could not call a slot in another thread like Qt can. It simply called the slot and if more threads were used then one had to implement handling race conditions (using mutex or such).
@JonB
Borland extended C++ introducing __closure keyword by which a class instance pointer (this) and a member method pointer could be bound together. Thus a function pointer could be used for a non member or a member method. Thus it does not matter if buttonClickHandler is a method in a class. -
@aleksejs
Borland made it simple and thus easy to use. "Simple" means that 1 signal could have 0 or 1 slot (button->OnClick is the signal, buttonClickHandler is the slot). If one wanted to connect more slots to 1 signal then had to implement handling more slots (listeners) in the 1 connected slot. For a simple GUI 1 slot was enough of course. "Simple" also means that threads were not considered at all, it could not call a slot in another thread like Qt can. It simply called the slot and if more threads were used then one had to implement handling race conditions (using mutex or such).
@JonB
Borland extended C++ introducing __closure keyword by which a class instance pointer (this) and a member method pointer could be bound together. Thus a function pointer could be used for a non member or a member method. Thus it does not matter if buttonClickHandler is a method in a class.@Szamo
Well I cannot comment if Borland C++ required an extension to C++ to achieve something. That is not the way to go at least these days. And I don't think it was available on non-Windows platforms.The restrictions you describe about 1 signal -> 1 slot would limit me compared to Qt. I would have to implement the multi-slot-handling queue. Similarly if I wanted to use threads. So of course Borland's code looks "simpler", because it is simpler and may require you to do more coding.
For my own part I don't find Qt's signals/slots "cumbersome". If someone likes the syntax of
button->OnClick = buttonClickHandlerrather than theconnect(....)statements look at Python/PySide/PyQt which implements a style ofbutton.onClick.connect(handler)instead. So the detail of connecting is "syntactic sugar", one could implement some kind of Borland/Python-style wrapper if wanted.