qt_demoe/tool/netserver/api/appconfig.cpp

59 lines
2.0 KiB
C++
Raw Normal View History

2021-04-13 01:36:22 +00:00
#include "appconfig.h"
2021-06-08 11:02:49 +00:00
#include "quihelper.h"
2021-04-13 01:36:22 +00:00
QString AppConfig::ConfigFile = "config.ini";
int AppConfig::ListenPort1 = 6907;
int AppConfig::CmdStart1 = 76;
int AppConfig::CmdLen1 = 12;
bool AppConfig::HexData1 = false;
2021-10-10 01:54:15 +00:00
2021-04-13 01:36:22 +00:00
int AppConfig::ListenPort2 = 6908;
int AppConfig::CmdStart2 = 76;
int AppConfig::CmdLen2 = 12;
bool AppConfig::HexData2 = false;
void AppConfig::readConfig()
{
QSettings set(AppConfig::ConfigFile, QSettings::IniFormat);
2021-10-10 01:54:15 +00:00
set.beginGroup("AppConfig1");
AppConfig::ListenPort1 = set.value("ListenPort1", AppConfig::ListenPort1).toInt();
AppConfig::CmdStart1 = set.value("CmdStart1", AppConfig::CmdStart1).toInt();
AppConfig::CmdLen1 = set.value("CmdLen1", AppConfig::CmdLen1).toInt();
AppConfig::HexData1 = set.value("HexData1", AppConfig::HexData1).toBool();
set.endGroup();
set.beginGroup("AppConfig2");
AppConfig::ListenPort2 = set.value("ListenPort2", AppConfig::ListenPort2).toInt();
AppConfig::CmdStart2 = set.value("CmdStart2", AppConfig::CmdStart2).toInt();
AppConfig::CmdLen2 = set.value("CmdLen2", AppConfig::CmdLen2).toInt();
AppConfig::HexData2 = set.value("HexData2", AppConfig::HexData2).toBool();
2021-04-13 01:36:22 +00:00
set.endGroup();
2021-09-28 07:05:38 +00:00
//配置文件不存在或者不全则重新生成
if (!QUIHelper::checkIniFile(AppConfig::ConfigFile)) {
writeConfig();
return;
}
2021-04-13 01:36:22 +00:00
}
void AppConfig::writeConfig()
{
QSettings set(AppConfig::ConfigFile, QSettings::IniFormat);
2021-10-10 01:54:15 +00:00
set.beginGroup("AppConfig1");
2021-04-13 01:36:22 +00:00
set.setValue("ListenPort1", AppConfig::ListenPort1);
set.setValue("CmdStart1", AppConfig::CmdStart1);
set.setValue("CmdLen1", AppConfig::CmdLen1);
set.setValue("HexData1", AppConfig::HexData1);
2021-10-10 01:54:15 +00:00
set.endGroup();
set.beginGroup("AppConfig2");
2021-04-13 01:36:22 +00:00
set.setValue("ListenPort2", AppConfig::ListenPort2);
set.setValue("CmdStart2", AppConfig::CmdStart2);
set.setValue("CmdLen2", AppConfig::CmdLen2);
set.setValue("HexData2", AppConfig::HexData2);
set.endGroup();
}