Qt中radio button的信號

Qt官網中說的很清楚,當radio button的狀態發生變化時,會發出toggled(bool)信號。
所以,當需要選擇radio button被選中時才發出的信號應選擇clicked(bool)信號。
Qt中關於radio button的信號有如下幾種(詳見官網)
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";
}

參考:
Qt radio button 官網

https://blog.csdn.net/xiaopang1122/article/details/81013349

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章