SIGNAL_SLOT - Unused connect cost?
-
Hi,
This is a general Qt question, does it "cost" something to do a connect on two QObject, (memory, error possibilities, ..)?
The reason i'm asking is that I have a lot of connect to do, I could do less because a lot of time the SIGNAL is not used in particular use case, so I could do (if, elseif) and connect only the necessary QObject together.. However this mean more coding and if it's not usefull I will just connect all the possible QObject together.
Hope i'm clear, thanks!
code sample :
@ /// WorkoutPlot_Hr
connect(this, SIGNAL(updateHrCurve(double, int)), ui->widget_workoutPlot_HeartrateZoom, SLOT(updateCurve(double, int)) );
connect(this, SIGNAL(targetHrChanged(int, int)), ui->widget_workoutPlot_HeartrateZoom, SLOT(targetChanged(int, int)) );
/// InfoBox HR
connect(this, SIGNAL(targetHrChanged(int, int)), ui->widget_infoBoxHr, SLOT(targetChanged(int, int)) );
connect(dataWorkout, SIGNAL(maxHrIntervalChanged(double)), ui->widget_infoBoxHr, SLOT(maxIntervalChanged(double)) );
connect(dataWorkout, SIGNAL(maxHrWorkoutChanged(double)), ui->widget_infoBoxHr, SLOT(maxWorkoutChanged(double)) );
connect(dataWorkout, SIGNAL(avgHrIntervalChanged(double)), ui->widget_infoBoxHr, SLOT(avgIntervalChanged(double)) );
connect(dataWorkout, SIGNAL(avgHrWorkoutChanged(double)), ui->widget_infoBoxHr, SLOT(avgWorkoutChanged(double)) );@ -
I don't know any specifics but I guess if you do an "emit" call if will just invoke all the slot functions, so there is a cost, but usually nothing more than a simple function call with direct connections. If you never emit a signal there should be no cost at all, of course the connection itself will be stored in memory but that should only be a few bytes, so unless you have millions of connection it should not matter much!?
if you have many unused connections maybe you can do a "delayed connect", before you do the first emit connect the objects there, if possible?
I don't know if there is any good and easy way to determine if a signals has any connections before you do the emit, I would like to know that too :)