嘿!我尝试执行以下操作
QList<QButtonGroup*> groups;
for (int i=0; i<nGroup; i++)
{
QButtonGroup *objects = new QButtonGroup(this);
objects->setExclusive(false);
for (int j=0; j<nObject; j++)
{
Led *tempLed = new Led();
tempLed->setAutoExclusive(false);
layout->addWidget(tempLed,j,i,Qt::AlignLeft);
objects->addButton(tempLed);
}
groups.append(objects);
}
然后尝试做这样的事情:
groups.at(1)->button(2)->setChecked(true);
代码编译,但在运行时抛出未处理的异常。我究竟做错了什么?有没有更好的方法来创建 QButtonGroup 组?