Qt slot with default argument

I have a spin control unit that changes the individual elements of the array. Instead of having separate functions of the receiver socket, I just wanted to indicate which control sent the message in the signal

You can do this with QSignalMapper - but is there a way to do this simply as shown below?

spin0 = new QDoubleSpinBox; connect(spin0,SIGNAL(valueChanged(double)),this,SLOT(handler(0,double)); spin1 = new QDoubleSpinBox; connect(spin1,SIGNAL(valueChanged(double)),this,SLOT(handler(1,double)); .... private slot: void handler(int element,double value); 
+4
source share
2 answers

From any slot handler, you can use sender () to get a pointer to the object that sent the signal. You can then use the objectName () property to pass any additional identifying information.

+3
source

I don’t believe it, at least I don’t use this syntax ... the SIGNAL and SLOT macros turn their arguments into strings, which are then parsed and used by the Qt framework to find related functions and / or classes in the tables created by moc during the preprocessing phase compilation. Therefore, if you encoded the default argument in the SLOT macro, then this is not a valid function signature that Qt can use to search in time for the actual slot function in the tables of moc generated functions.

+1
source

Source: https://habr.com/ru/post/1397905/


All Articles