Qt官網中說的很清楚,當radio button的狀態發生變化時,會發出toggled(bool)信號。
所以,當需要選擇radio button被選中時才發出的信號應選擇clicked(bool)信號。
Qt中關於radio button的信號有如下幾種(詳見官網)
有一個錯誤的代碼供大家參考。(使用toggled(bool) 和 clicked(bool)分別對槽函數進行連接,運行結果是不一樣的。)
void MainWindow::RBBluetoothOpen(){
if(ui->radioButton_bluetooth_close->isChecked()){
ui->radioButton_bluetooth_close->setChecked(false);
}
qDebug() << "radio open";
}
void MainWindow::RBBluetoorhClose(){
if(ui->radioButton_bluetooth_open->isChecked()){
ui->radioButton_bluetooth_open->setChecked(false);
}
qDebug() << "radio close";
}