Name your buttons in designer radioButton_X with X as your id, use a loop in your code to add them to QButtonGroup later on:
QButtonGroup *bg = ... for (int i = 1; i <= maxCount; ++i) { auto button = findChild<QRadioButton*>(QString("radioButton_%1").arg(i)); if (button) { bg->addButton(button, id); } else { qWarning() << "Something went wrong"; } }or directly address them
const auto buttons = { ui->radioButton_1, ui->radioButton_2, ... }; int id = 1; for (auto button : buttons) bg->addButton(button, id++);