#include "dialog.h" #include "QtCore/qdir.h" #include "QtCore/qjsonarray.h" #include "ui_dialog.h" #include "QMessageBox" #include Dialog::Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog) { ui->setupUi(this); } Dialog::~Dialog() { delete ui; } void Dialog::addDataToJsonFile(const QString& path, const QJsonObject& newData) { QString config_path=path+"/config.json"; QString Hotupdate_path=path+"/Hotupdate.json"; QFile file(config_path); QJsonDocument jsonDoc(newData); if (file.open(QIODevice::WriteOnly)) { file.write(jsonDoc.toJson()); file.close(); qDebug() << "JSON file created successfully."; } else { qDebug() << "Failed to create JSON file."; } //创建hot QJsonArray childrenArray; // 创建包含 "children" 数组的 JSON 对象 QJsonObject jsonObject; jsonObject["children"] = childrenArray; QFile file1(config_path); QJsonDocument jsonDoc1(jsonObject); if (file1.open(QIODevice::WriteOnly)) { file1.write(jsonDoc1.toJson()); file1.close(); qDebug() << "JSON file created successfully."; } else { qDebug() << "Failed to create JSON file."; } } void Dialog::on_pushButton_clicked() { this->close(); } void Dialog::on_pushButton_2_clicked() { // 执行相应的操作 QString dirPath = "~/Documents/RedInterstitialData/Hotupdate2/"; QJsonObject newData; QString pro_name=ui->pro_name->toPlainText(); QString app_id=ui->app_id->toPlainText(); QString config_server_pre=ui->config_server_pre->toPlainText(); QString file_serverpre=ui->file_serverpre->toPlainText(); // if(pro_name.isEmpty()) // { qDebug()<<"1111"; // ui->pro_name->setStyleSheet("QLineEdit{border:2px solid rgb(255, 0, 0);}"); // QString str = QString::fromLocal8Bit("Must Not Null"); // ui->pro_name->setToolTip(str); // return; // } if(pro_name.isEmpty()||app_id.isEmpty()||config_server_pre.isEmpty()||file_serverpre.isEmpty()) { QMessageBox messageBox; messageBox.setModal(false); messageBox.setText("请将信息填写完整"); messageBox.exec(); return; } QDir dir; if (!dir.mkpath(dirPath+pro_name)) { qDebug() << "Failed to create folder"; } QString filePath = dirPath+pro_name; newData.insert("pro_name", pro_name); newData.insert("app_id", app_id); newData.insert("config_server_pre", config_server_pre); newData.insert("file_serverpre", file_serverpre); addDataToJsonFile(filePath,newData); this->close(); }