You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
newValue/tpvs17/lpMain/lpGlobalConfig.cpp

64 lines
1.9 KiB
C++

4 years ago
#include "lpGlobalConfig.h"
#include <QApplication>
#include <QFile>
#include <QJsonObject>
#include <QJsonDocument>
#include <QJsonArray>
4 years ago
lpGlobalConfig::lpGlobalConfig(QObject *parent)
: QObject(parent)
{
m_rootPath = QApplication::applicationDirPath();
4 years ago
}
lpGlobalConfig::~lpGlobalConfig()
{
}
void lpGlobalConfig::readConfig()
{
QString strPath = m_rootPath + "/user/globalConfig.json";
QFile file(strPath);
if (true == file.open(QIODevice::ReadOnly))
{
QByteArray readData = file.readAll();
QJsonObject rootObj = QJsonDocument::fromJson(readData).object();
if (!rootObj.isEmpty())
{
QString strCam1 = rootObj.value("station_camkey_1").toString();
QString strCam2 = rootObj.value("station_camkey_2").toString();
QString strSolution1 = rootObj.value("station_solution_1").toString();
QString strSolution2 = rootObj.value("station_solution_2").toString();
QString strRunModel1 = rootObj.value("station_runModel_1").toString();
QString strRunModel2 = rootObj.value("station_runModel_2").toString();
m_StationCamKey_1 = strCam1;
m_StationCamKey_2 = strCam2;
m_StationSolution_1 = strSolution1;
m_StationSolution_2 = strSolution2;
m_StationRunModel_1 = strRunModel1;
m_StationRunModel_2 = strRunModel2;
}
}
file.close();
4 years ago
}
void lpGlobalConfig::writeConfig()
{
QString strPath = m_rootPath + "/user/globalConfig.json";
QFile file(strPath);
if (true == file.open(QIODevice::WriteOnly))
{
QJsonObject rootObj;
rootObj.insert("station_camkey_1", m_StationCamKey_1);
rootObj.insert("station_camkey_2", m_StationCamKey_2);
rootObj.insert("station_solution_1", m_StationSolution_1);
rootObj.insert("station_solution_2", m_StationSolution_2);
rootObj.insert("station_runModel_1", m_StationRunModel_1);
rootObj.insert("station_runModel_2", m_StationRunModel_2);
QJsonDocument doc(rootObj);
QByteArray writeData = doc.toJson();
file.write(writeData);
}
file.close();
4 years ago
}