1、首先拖动一个checkBox按钮放在界面上,然后就是需要,选择转到槽中的槽函数,如下,选择这个
2、代码部分:
1 void MainWindow::on_checkBox_stateChanged(int arg1) 2 { 3 //第一种
4 if(arg1 == 2) 5 { 6 qDebug()<<"表示被选中1"; 7 } 8 else if(arg1 == 0) 9 { 10 qDebug()<<"表示未被选中"; 11 } 12
13 //第二种
14 bool status =ui->checkBox->isChecked(); 15 qDebug()<<"status"<<status; 16 if(status == true) 17 { 18 qDebug()<<"表示被选中2"; 19
20 } 21 else if(status == false) 22 { 23 qDebug()<<"表示未被选中2"; 24 } 25 }
结果如下: