Using variables to acces UI

  • HI Guys,
    I'm new to Qt

    I have about 50 buttons in my UI, and I need to modify them if the certain condition is met,

    void aaa::on_push_button1_clicked()

    this one works well, but so I wil have to manually check for every button, so I want to replace pushButton_00 with a variable, but I can't get it to work

  • Qt Champions 2017

    Hi and welcome
    There is a special sender() in a slot you can use to know which button was the sender of
    the clicked() signal

    void aaa::on_push_button1_clicked()
    QPushButton *butt=qobject_cast<QPushButton *> ( sender() ) ;
    if (butt) {

    that way u can use a variable and not ui->NAME

    All you buttons should be connected to same slot then.

    You could do that after setupUI()

    QList<QPushButton *> list = this->findChildren<QPushButton *>();
    foreach(QPushButton *b, list) {
    connect(b, XXX

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.