Should i avoid Signals?
-
Does signals have a 'heavy' impact in my program performance?
In the background how does it really works? is it something that is constantly checked?
Should i avoid creating lambda connections whenever possible or do they have a 'minimal' impact and its ok to use it?
For example:
connect(ui.Button, &SpinnerButton::signalLogin, [this]() { .... });
-
Does signals have a 'heavy' impact in my program performance?
It depends what "heavy" means for you. Is it 100ms? 10? less then 1? As always - if in doubt use a profiler.
In the background how does it really works?
It's a bit of a lenghty topic. For details see e.g. this 3-part article: How Qt Signals and Slots Work.
In short when slot is called on the same thread it's just a direct function call with a bit of lookup logic overhead. If slot is to be called on another thread it is put in a queue for that thread and parameters are potentially copied (depending on their type), so there's thread synchronization involved.is it something that is constantly checked?
Not at all. As mentioned above on same thread it's just a function call. On different threads it's a slot queue checked in the event loop when there's anything to call.
Should i avoid creating lambda connections whenever possible or do they have a 'minimal' impact and its ok to use it?
"minimal" is, again, very relative. Generally it's just a function pointer stored in the connection object, so something along the lines of std::function. Yet again, if in doubt - profile.
connect(ui.Button, &SpinnerButton::signalLogin, [this]()
It's a good practice to use the 4 parameter version of the connect function. Especially if you're using some objects in your lambda you should tie the lifetime of that connection to the lifetime of that object, e.g.
connect(ui.Button, &SpinnerButton::signalLogin, this, [this]() { this->doStuff(); });
otherwise, if
this
is destroyed while button still exists the connection can be triggered and that lambda will crash.