Just implement a
QPushButton::clicked()
slot that is connected to multiple push buttons. Inside that cast
sender()
to
QPushButton*
to access the button and identify it. You can then emit a user defined signal with additional parameters.
Another method would be using a C++11 lambda:
int counter = 1;
button->setProperty("myId", counter++);
connect(button, &QPushButton::clicked, [this, button](){
qDebug() << button->property("myId").toString();
ui->label->setText(button->text());
});
The above is using the property system to provide IDs, printing it to the debug window and setting a label to the button's caption text.