可以将多个信号绑定到一个插槽(不是?).那么,有没有办法了解哪个小部件发送信号?我正在寻找像sender.NET中的事件参数之类的东西
小智 118
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 )
{
...
}
}
Run Code Online (Sandbox Code Playgroud)