add default json file

This commit is contained in:
xueyan hu
2022-01-21 11:06:10 +08:00
parent 54e1539783
commit b53ce5caf8
3 changed files with 28 additions and 4 deletions

View File

@@ -9,7 +9,7 @@
#include <QApplication>
#include "json/cJSON.h"
const char* strProductFileName = "./cfgs/usct-product.json";
const char* strProductFileNameDefault = "./cfgs/usct-product";
JsonObject::JsonObject()
{
loadcfg();
@@ -243,8 +243,32 @@ bool JsonObject::loadcfg()
{
if (m_bLoaded)
return true;
std::ifstream inFile(strProductFileName);
if (!inFile.is_open())
{
return loadcfgDefault();
}
std::stringstream ss;
ss << inFile.rdbuf();
std::string strJsonData = ss.str();
json_root = cJSON_Parse(strJsonData.c_str());
inFile.close();
if (!json_root)
return loadcfgDefault();
m_bLoaded = true;
return true;
}
bool JsonObject::loadcfgDefault()
{
std::ifstream inFile(strProductFileNameDefault);
if (!inFile.is_open())
{
return false;
}
@@ -252,8 +276,8 @@ bool JsonObject::loadcfg()
ss << inFile.rdbuf();
std::string strJsonData = ss.str();
json_root = cJSON_Parse(strJsonData.c_str());
inFile.close();
if (!json_root)
return false;
@@ -261,7 +285,6 @@ bool JsonObject::loadcfg()
return true;
}
bool JsonObject::savecfg()
{
if (!m_bLoaded)

View File

@@ -110,6 +110,7 @@ private:
bool loadcfg();
bool loadcfgDefault();
bool savecfg();
JsonObject();

View File

@@ -92,7 +92,7 @@ int main(int argc, char* argv[])
redir.moveToThread(&thread);
QObject::connect(&Timer, SIGNAL(timeout()), &redir, SLOT(readOutsToTF()));
fflush(stdout);
Timer.start(10000);
Timer.start(1000);
thread.start();