qt QGroupBox radiobutton

QGroupBox

显示文本:属性 title

加载radiobutton

cpp 复制代码
    if (jsonObject.contains("startEndTogether") && jsonObject["startEndTogether"].isString()) {
           QString selectedButton = jsonObject["startEndTogether"].toString();

           // Iterate through the children of groupBox_2 to find the QRadioButton
           const QObjectList &children = ui->groupBox_2->children();
           for (QObject *child : children) {
               QRadioButton *radioButton = qobject_cast<QRadioButton*>(child);
               if (radioButton) {
                   // Check if the radio button's object name matches the value from jsonObject
                   if (radioButton->objectName() == "radioButton_3" &&  selectedButton == "1") {

                       radioButton->setChecked(true);
                   } else if (radioButton->objectName() == "radioButton_4" &&  selectedButton == "2") {
                       radioButton->setChecked(true);
                   }
               }
           }
    }

读取radiobutton保存json

cpp 复制代码
  jsonObject["testType"] =  "考核";
    jsonObject["deviceNumber"] =  "deviceNumber";
    jsonObject["turns"] = ui->turns->toPlainText();
    jsonObject["capacity"] = ui->capacity->toPlainText();
    jsonObject["minDuration"] = ui->minDuration->toPlainText();
    jsonObject["startEndTogether"] =  "2";
    jsonObject["recodePosition"] =  "1";
    jsonObject["userIds"] = "userIds";

    const QObjectList &children = ui->groupBox_2->children();
    for (QObject *child : children) {
        if (QRadioButton *radioButton = qobject_cast<QRadioButton*>(child)) {
            if (radioButton->isChecked()){
                if (radioButton->objectName()=="radioButton_3"){
                    jsonObject["startEndTogether"] =  "1";
                }
            }
        }
        // Add other widget types as needed
    }

    const QObjectList &children_2 = ui->groupBox->children();
    for (QObject *child : children_2) {
        if (QRadioButton *radioButton = qobject_cast<QRadioButton*>(child)) {
            if (radioButton->isChecked()){
                if (radioButton->objectName()=="startEndTogether_1"){
                    jsonObject["recodePosition"] =  "0";
                }
            }

        }
        // Add other widget types as needed
    }

    // Optionally, print JSON object for debugging
    QJsonDocument doc(jsonObject);
    QString jsonString = doc.toJson(QJsonDocument::Compact);
    qDebug() << "Current JSON:" << jsonString;
    QFile saveFile(config_path);

    if (!saveFile.open(QIODevice::WriteOnly)) {
        qWarning("Couldn't open save file.");
        return;
    }

    QJsonDocument saveDoc(jsonObject);
    saveFile.write(saveDoc.toJson());
    saveFile.close();
相关推荐
m0_63152982几秒前
golang如何实现目录大小统计_golang目录大小统计实现方案
jvm·数据库·python
运维行者_2 分钟前
理解应用性能监控
大数据·服务器·网络·数据库·人工智能·网络协议·安全
2301_769340673 分钟前
Golang怎么限制请求Body大小_Golang如何防止客户端发送过大的请求体【避坑】
jvm·数据库·python
AgentOPC4 分钟前
Cerebras WSE-3 vs Nvidia H100/H200/B200:详细技术对比——谁才是 AI 时代真正的“芯片之王“
开发语言·人工智能·nvidia
qq_2518364577 分钟前
基于java 汽车检修管理系统设计与实现 论文
java·开发语言·汽车
lbaihao8 分钟前
LLVM Cpu0 调用规则解析
开发语言·前端·python·llvm
基德爆肝c语言10 分钟前
Qt系统相关
开发语言·qt
Jetev11 分钟前
Django怎么优雅发送邮件_Python配置SMTP后端实现异步通知
jvm·数据库·python
redaijufeng13 分钟前
C/C++程序从编译到链接的过程
c语言·开发语言·c++
woxihuan12345616 分钟前
golang如何读写YAML配置文件_golang YAML配置文件读写解析
jvm·数据库·python