我正在为学校做一个小组项目。我的小组成员创建了一个窗口,里面有大约75个单选按钮。我想在按下按钮时强制所有单选按钮都变为“清除”或“未选中”状态。
有人知道如何做到这一点吗?我一直在研究QObjectList,但是我不能简单地使用QObjectList *children = new QObjectList(ui->groupBox->children());并使用for循环对它们进行循环,因为QObjectList似乎没有next方法。
我还尝试过类似以下的操作:
QObjectList *children = new QObjectList(ui->groupBox->children());
for(QObject *iterator = children.first(); iterator!=NULL; children.pop_front()){
iterator = children.first();
iterator->at(0)->setCheckabled(false);
}
但是由于迭代器是QObject,所以setCheckable不像单选按钮那样存在。
欢迎提供想法/提示。
编辑:我甚至可以接受一个提示,以便遍历具有类似名称的变量。例如,我的所有单选按钮都命名为RadioButton_1、RadioButton_2等。