Why not ...
MainWindow
::MainWindow(QWidget *parent
){
ui->setupUi(this);
...
//QPushButton *buttonx[9];
buttonx[0] = ui->b1;
buttonx[1] = ui->b2;
buttonx[2] = ui->b3;
buttonx[3] = ui->b4;
buttonx[4] = ui->b5;
buttonx[5] = ui->b6;
buttonx[6] = ui->b7;
buttonx[7] = ui->b8;
buttonx[8] = ui->b9;
//http://doc.trolltech.com/qq/qq10-signalmapper.html
//The Signal Mapper Approach
connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(myButtonPressed(int)));
for(int i = 0; i < 9; i++){
signalMapper->setMapping(buttonx[i], i + 1);
connect(buttonx[i], SIGNAL(clicked()), signalMapper, SLOT(map()));
}
...
}
...
void MainWindow::myButtonPressed(int m){
//use one specific button
//iterate the array to use all
}
...
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindowClass)
{
ui->setupUi(this);
...
//QPushButton *buttonx[9];
buttonx[0] = ui->b1;
buttonx[1] = ui->b2;
buttonx[2] = ui->b3;
buttonx[3] = ui->b4;
buttonx[4] = ui->b5;
buttonx[5] = ui->b6;
buttonx[6] = ui->b7;
buttonx[7] = ui->b8;
buttonx[8] = ui->b9;
//http://doc.trolltech.com/qq/qq10-signalmapper.html
//The Signal Mapper Approach
QSignalMapper *signalMapper = new QSignalMapper(this);
connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(myButtonPressed(int)));
for(int i = 0; i < 9; i++){
signalMapper->setMapping(buttonx[i], i + 1);
connect(buttonx[i], SIGNAL(clicked()), signalMapper, SLOT(map()));
}
...
}
...
void MainWindow::myButtonPressed(int m){
//use one specific button
//iterate the array to use all
}
...
To copy to clipboard, switch view to plain text mode
Bookmarks