#include "lpGlobalConfig.h" #include #include #include #include #include lpGlobalConfig::lpGlobalConfig(QObject *parent) : QObject(parent) { m_rootPath = QApplication::applicationDirPath(); } 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(); } 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(); }