There is a QStringList , there are, for example, 9 elements (in general there can be as many as you like). It is necessary to create dynamically buttons depending on the number of elements in QStringList . Each button has the name of its element in QStringList , arrange them in layout 3x3. Further, when you click on each button to process the signal in its own way. For example, when you press button 5, the line “you clicked button 5” is displayed, and by pressing button 2 , 2 variables are added and the answer is displayed in qDebug() .

Actually, one of the problems: how to fasten buttons that have not yet been created to the slots? After all, we do not know in advance how many elements in QStringList but each button should have its own command. Which is required.

  • one
    And what prevents in the code after creating the button to call QObject::connect ? - user194374
  • one
    Everything seems understood how to solve this problem. I climbed on the off-dock and found the QSignalMapper class, I can still use Lambda. You can also use the construction of the DynButton * button = (DynButton *) sender () slot, which determines the object that caused the signal and continue to work with it already. - Disastricks

0