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();
相关推荐
forestsea10 分钟前
MySQL 调优
数据库·mysql·性能优化
Java手札27 分钟前
Windows下Golang与Nuxt项目宝塔部署指南
开发语言·windows·golang
小生凡一29 分钟前
腾讯二面:TCC分布式事务 | 图解TCC|用Go语言实现一个TCC
开发语言·分布式·golang
minji...33 分钟前
C语言 函数递归
c语言·开发语言·算法
云上空1 小时前
C#初级知识总结
开发语言·c#
松树戈1 小时前
PostgreSQL使用LIKE右模糊没有走索引分析&验证
数据库·postgresql
文牧之1 小时前
PostgreSQL 常用日志
运维·数据库·postgresql
钢铁男儿1 小时前
C# 深入理解类:面向对象编程的核心数据结构
开发语言·数据结构·c#
karatttt1 小时前
用go从零构建写一个RPC(仿gRPC,tRPC)--- 版本1
后端·qt·rpc·架构·golang
TE-茶叶蛋2 小时前
Redis 原子操作
数据库·redis·缓存