我在 groupbox 中有很多单选按钮,我想获取选中的单选按钮的文本数据。但是我不想写很多“else if”,我的意思是;
if (ui->radiobutton->isChecked)
// method's
else if (ui->radiobutton->isCheked)
// method's
..
..
有什么方法可以让我了解在特定的组框中选中了哪个单选按钮?如果可能的话,你能给我举个例子吗?
最佳答案
您可以使用 QButtonGroup 作为父级:http://doc.qt.io/qt-5/qbuttongroup.html#checkedButton
QAbstractButton * QButtonGroup::checkedButton() const
Returns the button group's checked button, or 0 if no buttons are checked.
See also buttonClicked().
关于c++ - 如何从qt中的单选按钮获取值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30081160/