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();
相关推荐
小叶学C++几秒前
【C++】类与对象(下)
java·开发语言·c++
ac-er88882 分钟前
PHP“===”的意义
开发语言·php
Cikiss14 分钟前
微服务实战——平台属性
java·数据库·后端·微服务
jk_10120 分钟前
MATLAB中decomposition函数用法
开发语言·算法·matlab
weixin_4640780721 分钟前
C#串口温度读取
开发语言·c#
无敌の星仔23 分钟前
一个月学会Java 第2天 认识类与对象
java·开发语言
小小不董28 分钟前
《Linux从小白到高手》理论篇:深入理解Linux的网络管理
linux·运维·服务器·数据库·php·dba
豆豆1 小时前
为什么用PageAdmin CMS建设网站?
服务器·开发语言·前端·php·软件构建
无敌少年小旋风1 小时前
MySQL 内部优化特性:索引下推
数据库·mysql
柒小毓1 小时前
将excel导入SQL数据库
数据库