可以将多个信号绑定到一个槽(是吧?)。那么,有没有办法知道是哪个小部件发送了信号呢?我在寻找类似于.NET中事件的
sender
参数的东西。sender
参数的东西。QObject::sender()
,就像以下示例中所示:void MainWindow::someSetupFunction( void )
{
...
connect( _foobarButton, SIGNAL(clicked()), this, SLOT(buttonPressedSlot()) );
}
void MainWindow::buttonPressedSlot()
{
// e.g. check with member variable _foobarButton
QObject* obj = sender();
if( obj == _foobarButton )
{
...
}
// e.g. casting to the class you know its connected with
QPushButton* button = qobject_cast<QPushButton*>(sender());
if( button != NULL )
{
...
}
}