add save config file error reminder
This commit is contained in:
parent
0770af3c7b
commit
2e87b56d44
@ -3,7 +3,7 @@
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include <QMessageBox>
|
||||
#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) {
|
||||
|
||||
@ -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<CardBase> GetSlotPtr(int slot);//1-15
|
||||
void AddCard(std::shared_ptr<CardBase> ptr);
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user