Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to implement multiple , same widgets, in "loop "?



  • I have the following test code setting "TEST trace" text in consecutive widgets.

    I am asking for suggestions on how to implement the code using "loop" - in QCreator.

    As an example - I like to be able to "clear()" the text in such loop.

    From other resources - one way to do that is to have "parent widget" and iterate thru children.

    // test tabs
    ui->chat_2->setText("TEST trace ");
    ui->chat_3->setText("TEST trace ");
    ui->chat_4->setText("TEST trace ");
    ui->chat_5->setText("TEST trace ");
    ui->chat_6->setText("TEST trace ");



  • @AnneRanch
    Hi
    like this!

    QList<QPushButton*> pushButtons = findChildren<QPushButton*>();
    foreach (QPushButton*pBut, pushButtons) {
        if ( pBut )
        {
            pBut->setText("HI");
        }
    }
    

    here is only an example!



  • @AnneRanch
    Hi
    like this!

    QList<QPushButton*> pushButtons = findChildren<QPushButton*>();
    foreach (QPushButton*pBut, pushButtons) {
        if ( pBut )
        {
            pBut->setText("HI");
        }
    }
    

    here is only an example!



  • @CP71 Thanks, works perfectly.


Log in to reply