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();
相关推荐
老毛肚1 分钟前
Redis八股
数据库·redis·缓存
故事和你912 分钟前
sdut-程序设计基础Ⅰ-期末测试(重现)
大数据·开发语言·数据结构·c++·算法·蓝桥杯·图论
Sarvartha3 分钟前
AI 软件开发之编排与评估优化
数据库·人工智能
重庆兔巴哥6 分钟前
如何在Dev-C++中使用MinGW-w64编译器?
linux·开发语言·c++
魔道不误砍柴功7 分钟前
Java Function 高级使用技巧:从工程实战中来
java·开发语言·python
三佛科技-187366133978 分钟前
LP3783A芯茂微5V2.1A低功耗原边反馈充电器芯片替代PL3378/C
c语言·开发语言
不知名。。。。。。。。8 分钟前
仿muduo库实现高并发服务器----EventLoop与线程整合起来
java·开发语言·jvm
编程大师哥11 分钟前
JAVA 集合框架进阶
java·开发语言
xixihaha132412 分钟前
使用Flask快速搭建轻量级Web应用
jvm·数据库·python
春日见14 分钟前
车载系统中的CPU与内存监管
java·开发语言·驱动开发·docker·计算机外设