c++ - 如何从qt中的单选按钮获取值?

标签 c++ qt radio-button groupbox

我在 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/

相关文章:

c++ - 滚动时的滚动条事件?

c++ - 是否有任何可观察的 Qt 容器类?

php - 获取单选按钮值并通过ajax发送到php

javascript - 在 If 语句条件 Javascript/jQuery 中嵌入 For 循环

c++ - 关于在 QT StyleSheet 中创建类似于聊天气泡的内容的建议/提示

css - 单选按钮复选框未在移动设备中排列

c++ - 覆盖要求后调用 `lua_getfield()` 时崩溃

c++ - 特定窗口c++的屏幕截图

c++ - C++ 中的 fstream 错误

javascript - Qt5-QML-AirLink RV50-JavaScript : How to automatically trigger combobox & button on a third party router