qt QGroupBox radiobutton

QGroupBox

显示文本:属性 title 

加载radiobutton

    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

  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();

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-06 00:58:09       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-06 00:58:09       101 阅读
  3. 在Django里面运行非项目文件

    2024-06-06 00:58:09       82 阅读
  4. Python语言-面向对象

    2024-06-06 00:58:09       91 阅读

热门阅读

  1. 双向链表MyLinkList

    2024-06-06 00:58:09       25 阅读
  2. Unknown module(s) in QT: texttospeech

    2024-06-06 00:58:09       30 阅读
  3. Vue的过滤器是什么如何使用它

    2024-06-06 00:58:09       29 阅读
  4. Git配置SSH-Key

    2024-06-06 00:58:09       28 阅读
  5. rose 聊开源—1 你为什么需要一个开源项目

    2024-06-06 00:58:09       25 阅读
  6. django接入djangorestframework-simplejwt步骤

    2024-06-06 00:58:09       31 阅读
  7. blender从视频中动作捕捉,绑定到人物模型

    2024-06-06 00:58:09       24 阅读
  8. 随心笔记,第四更

    2024-06-06 00:58:09       19 阅读
  9. AIGC工具汇总介绍

    2024-06-06 00:58:09       30 阅读
  10. Blender 学习笔记(一)快捷键记录

    2024-06-06 00:58:09       26 阅读
  11. EasyExcel前端怎么使用:深度解析与实用指南

    2024-06-06 00:58:09       25 阅读