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();
相关推荐
Francek Chen39 分钟前
【大数据存储与管理】分布式数据库HBase:03 HBase数据模型
大数据·数据库·hadoop·分布式·hdfs·hbase
一方热衷.7 小时前
YOLO26-Seg ONNXruntime C++/python推理
开发语言·c++·python
小吴编程之路8 小时前
MySQL 索引核心特性深度解析:从底层原理到实操应用
数据库·mysql
靓仔建8 小时前
Vue3导入组件出错does not provide an export named ‘user_setting‘ (at index.vue:180:10)
开发语言·前端·typescript
~莫子8 小时前
MySQL集群技术
数据库·mysql
凤山老林8 小时前
SpringBoot 使用 H2 文本数据库构建轻量级应用
java·数据库·spring boot·后端
就不掉头发8 小时前
Linux与数据库进阶
数据库
与衫8 小时前
Gudu SQL Omni 技术深度解析
数据库·sql
咖啡の猫9 小时前
Redis桌面客户端
数据库·redis·缓存
oradh9 小时前
Oracle 11g数据库软件和数据库静默安装
数据库·oracle