diff --git a/config_mgr.cpp b/config_mgr.cpp index 1e9c817..dfab0ef 100644 --- a/config_mgr.cpp +++ b/config_mgr.cpp @@ -3,7 +3,7 @@ #include #include #include - +#include #include "data_config.h" #include "vibrationdata.h" #include "tachometer_data.h" @@ -18,7 +18,7 @@ ConfigMgr *ConfigMgr::instance = nullptr; ConfigMgr::~ConfigMgr() { } -void ConfigMgr::Save(QString & file_path) { +int ConfigMgr::Save(QString & file_path) { QJsonObject doc_obj; int slot = 0; QJsonArray card_type; @@ -590,8 +590,14 @@ void ConfigMgr::Save(QString & file_path) { jsonDoc.setObject(doc_obj); QFile file(file_path); file.open(QIODevice::WriteOnly); - file.write(jsonDoc.toJson()); + int ret = file.write(jsonDoc.toJson()); file.close(); + if(ret != 0){ + return -1; + }else{ + return 0; + } + } void ConfigMgr::Load(QString filename) { diff --git a/config_mgr.h b/config_mgr.h index d38f234..0ad1eae 100644 --- a/config_mgr.h +++ b/config_mgr.h @@ -122,7 +122,7 @@ class ConfigMgr { return instance; } ~ConfigMgr(); - void Save(QString & file_path); + int Save(QString & file_path); void Load(QString filename); std::shared_ptr GetSlotPtr(int slot);//1-15 void AddCard(std::shared_ptr ptr); diff --git a/mainwindow.cpp b/mainwindow.cpp index 6aa7eb7..0a1a71d 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -640,10 +640,16 @@ void MainWindow::on_pushButton_save_clicked() { if(filepath == "") return; file_name = filepath + "\\"+file_name +".json"; - ConfigMgr::Instance()->Save(file_name); + int ret = ConfigMgr::Instance()->Save(file_name); + if(ret != 0){ + QMessageBox::warning(this, QStringLiteral("提示"), QStringLiteral("文件保存失败!请检查文件权限!")); + } tsi_config_file = file_name; }else { - ConfigMgr::Instance()->Save(tsi_config_file); + int ret = ConfigMgr::Instance()->Save(tsi_config_file); + if(ret != 0){ + QMessageBox::warning(this, QStringLiteral("提示"), QStringLiteral("文件保存失败!请检查文件权限!")); + } } return;