Search code examples
c++qtsignals-slots

Qt slot with default argument


I have a block of spin controls which change individual elements of an array Rather than having separate receiver slot functions, I wanted to just specify which control sent the message in the signal

You can do this with a QSignalMapper - but is there anyway of doing it simply as 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);

Solution

  • From any slot handler you can can use sender() to get a pointer to the object that sent the signal. Then you can use the objectName() property to communicate any further identifying information.