Shortcut to brute force copy paste?

Hi, this is our first time creating a GUI as we have previously only used console applications. We have a lot of push buttons(81), and would like to read the text from any one of them, when any one is clicked. We know how to read the text using the text() function, but can't find a way without copying and pasting the syntax 81 times for each button.

1
2
3
4
5
6
7
8
9
10
11
12
13
void hardAI::on_button_1_clicked()
{
        QString buttonText;
        buttonText=ui->button_1->text();//get text from button1
}

void hardAI::on_button_2_clicked()
{
    QString buttonText;
    buttonText=ui->button_2->text();//get text from button2
}
//etc
Last edited on
bump
Why so impatient?


Perhaps you could add all those buttons to a QButtonGroup and then connect the group's buttonClicked signal to single handling function. (The signal has a pointer to the button that was clicked.)
Topic archived. No new replies allowed.