add save config file error reminder
This commit is contained in:
parent
0770af3c7b
commit
2e87b56d44
@ -3,7 +3,7 @@
|
|||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
#include <QMessageBox>
|
||||||
#include "data_config.h"
|
#include "data_config.h"
|
||||||
#include "vibrationdata.h"
|
#include "vibrationdata.h"
|
||||||
#include "tachometer_data.h"
|
#include "tachometer_data.h"
|
||||||
@ -18,7 +18,7 @@ ConfigMgr *ConfigMgr::instance = nullptr;
|
|||||||
ConfigMgr::~ConfigMgr() {
|
ConfigMgr::~ConfigMgr() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigMgr::Save(QString & file_path) {
|
int ConfigMgr::Save(QString & file_path) {
|
||||||
QJsonObject doc_obj;
|
QJsonObject doc_obj;
|
||||||
int slot = 0;
|
int slot = 0;
|
||||||
QJsonArray card_type;
|
QJsonArray card_type;
|
||||||
@ -590,8 +590,14 @@ void ConfigMgr::Save(QString & file_path) {
|
|||||||
jsonDoc.setObject(doc_obj);
|
jsonDoc.setObject(doc_obj);
|
||||||
QFile file(file_path);
|
QFile file(file_path);
|
||||||
file.open(QIODevice::WriteOnly);
|
file.open(QIODevice::WriteOnly);
|
||||||
file.write(jsonDoc.toJson());
|
int ret = file.write(jsonDoc.toJson());
|
||||||
file.close();
|
file.close();
|
||||||
|
if(ret != 0){
|
||||||
|
return -1;
|
||||||
|
}else{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigMgr::Load(QString filename) {
|
void ConfigMgr::Load(QString filename) {
|
||||||
|
|||||||
@ -122,7 +122,7 @@ class ConfigMgr {
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
~ConfigMgr();
|
~ConfigMgr();
|
||||||
void Save(QString & file_path);
|
int Save(QString & file_path);
|
||||||
void Load(QString filename);
|
void Load(QString filename);
|
||||||
std::shared_ptr<CardBase> GetSlotPtr(int slot);//1-15
|
std::shared_ptr<CardBase> GetSlotPtr(int slot);//1-15
|
||||||
void AddCard(std::shared_ptr<CardBase> ptr);
|
void AddCard(std::shared_ptr<CardBase> ptr);
|
||||||
|
|||||||
@ -640,10 +640,16 @@ void MainWindow::on_pushButton_save_clicked() {
|
|||||||
if(filepath == "")
|
if(filepath == "")
|
||||||
return;
|
return;
|
||||||
file_name = filepath + "\\"+file_name +".json";
|
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;
|
tsi_config_file = file_name;
|
||||||
}else {
|
}else {
|
||||||
ConfigMgr::Instance()->Save(tsi_config_file);
|
int ret = ConfigMgr::Instance()->Save(tsi_config_file);
|
||||||
|
if(ret != 0){
|
||||||
|
QMessageBox::warning(this, QStringLiteral("提示"), QStringLiteral("文件保存失败!请检查文件权限!"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user