Many PushButton
-
Hello, how can i to make this easier and shorter?
I have many PushButton (more then 100) and doing similar thing.public slots:
@
void MyForm::on_pb_1_clicked() { Methode(pb_1, Array[0]);}
void MyForm::on_pb_2_clicked() { Methode(pb_2, Array[1]);}
.
.
.
void MyForm::on_pb_n_clicked() { Methode(pb_n, Array[n-1]);}
@pb_1, .... pb_n is many pushbutton.
Edit: please use code tags, Andre
-
Example:
@
QSignalMapper *btnGroup;
btnGroup = new QSignalMapper(this);
connect(btnGroup, SIGNAL(mapped(int)), this, SIGNAL(btnOutClickSlot(int)));void myclass::btnOutClickSlot(int btn)
{
//code here
}QPushButton *tmp[2] = {pushButton,pushButton_2};
for (quint16 i = 0; i < 2; i++)
{
btnGroup->setMapping(pushB[i], i);
connect(tmp[i], SIGNAL(clicked()), btnGroup, SLOT(map()));
}
@ -
QSignalMapper is a perfect solution. TY!