如何从QT中的RadioButton获得价值

How to get value from radiobutton in qt?

本文关键字:RadioButton 中的 QT      更新时间:2023-10-16

我在GroupBox中有很多radiobutton,我想获取已检查的RadioButton的文本数据。但是我不想写很多"否则",我的意思是

if (ui->radiobutton->isChecked)
// method's 
else if (ui->radiobutton->isCheked)
// method's 
..
..

有什么办法可以理解在特定组箱中检查哪个RadioButton?如果可能的话,请给我一个例子吗?

您可以使用qbuttongroup作为父:http://doc.qt.io/qt-5/qbuttongroup.html#checkedbutton

qabstractbutton * qbuttongroup :: checkedbutton()const

返回按钮组的检查按钮,或0如果没有按钮 检查。

另请参见ButtonClicked()。