3个按键连接到同一个槽函数
connect(button1, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
connect(button2, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
connect(button3, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
使用sender()函数来确定是哪个按钮被点击:
void YourClass::onButtonClicked()
{
QPushButton *clickedButton = qobject_cast<QPushButton*>(sender());
if(clickedButton == button1) {
// 处理button1被点击的情况
} else if(clickedButton == button2) {
// 处理button2被点击的情况
} else if(clickedButton == button3) {
// 处理button3被点击的情况
}
}