PDA

View Full Version : Getting the pointer of a widget that emitted a signal in a slot



wconstan
7th December 2009, 17:34
I have a slot:


void myClass::on_eptErrorDSpin_valueChanged()
{
updateDesignMapQDoubleSpinBox(ui->eptErrorDSpin);
}


for a QDoubleSpin widget whose objectName is eptErrorDSpin. The function updateDesignMapQDoubleSpinBox() expects a pointer to QDoubleSpin object, which is accomplished by using ui->eptErrorDSpin in the call. Out of curiosity, is there an "easier" way for me to obtain the pointer to eptErrorDSpin? For example, does a slot know anything of the caller that emitted the signal? Put another way, can a slot obtain the pointer of the widget that emitted the signal without explicitly having to specify it as I have done above or is there another, more general, approach that I can use?

I was tinkering with the this pointer but don't know much about it.

Thanks!

spirit
7th December 2009, 18:49
take a look at QObject::sender.