如何验证是否选中了多个复选框

3 c++ checkbox qt ischecked

std::string output; 

if ((checkbox1->isChecked() && checkbox2->isChecked()) && 
   (!checkbox3->isChecked() || !checkbox4->isChecked() || !checkbox5->isChecked() || !checkbox6->isChecked()))
{
  output = " Using Checkbox: 1, 2 ";
}

if ((checkbox1->isChecked() && checkbox2->isChecked() && checkbox3->isChecked()) && 
   (!checkbox4->isChecked() || !checkbox5->isChecked() || !checkbox6->isChecked()))
{
  output = " Using Checkbox: 1, 2, 3 ";
}

....
Run Code Online (Sandbox Code Playgroud)

使用QT创建器如何验证已检查了多少个复选框并相应地更改输出字符串?由于我与所有那些NOT AND OR混淆,因此多个if语句无法正常工作.编码所有可能性需要很长时间.

Che*_*byl 13

所有你checkBoxes应该在groupBox

试试这个:

QList<QCheckBox *> allButtons = ui->groupBox->findChildren<QCheckBox *>();
qDebug() <<allButtons.size();
for(int i = 0; i < allButtons.size(); ++i)
{
    if(allButtons.at(i)->isChecked())
        qDebug() << "Use" << allButtons.at(i)->text()<< i;//or what you need
}
Run Code Online (Sandbox Code Playgroud)