1、不按顺序
QList<QRadioButton*>rbtList = this->findChildren<QRadioButton*>();// 或者 QList<QRadioButton*>rbtList = ui.groupBox1->findChildren<QRadioButton*>();
然后:
foreach (QRadioButton* rbt, rbtList)
{
rbt->setChecked(true);
}
2.按顺序
QList<QRadioButton*>rbtList;
rbtList<<ui.radioButton1<<ui.radioButton2<<ui.radioButton3<<ui.radioButton4<<ui.radioButton5<<ui.radioButton6;
然后
调用rbtList.at(i)进行对指定元素进行更改。