重新构建的批检仪主板程序
This commit is contained in:
108
base/mycfg.cpp
108
base/mycfg.cpp
@@ -18,7 +18,6 @@
|
||||
|
||||
// 配置文件
|
||||
#define CFG_FILE_NAME CFG_PATH+"cfg.json"
|
||||
#define CHECK_CFG_FILE_NAME cfg_->def_check_cfg
|
||||
|
||||
// 自启动路径
|
||||
#define AUTO_START_PATH "/usr/local/QDesktop-fb"
|
||||
@@ -282,20 +281,111 @@ void mycfg::init_env()
|
||||
|
||||
|
||||
|
||||
void mycfg::restart()
|
||||
{
|
||||
system("systemctl restart atk-qtapp-start.service");
|
||||
}
|
||||
|
||||
|
||||
|
||||
void mycfg::reload()
|
||||
{
|
||||
QFile file;
|
||||
file.setFileName(CFG_FILE_NAME);
|
||||
if(!file.exists())
|
||||
{
|
||||
file.open(QIODevice::ReadWrite);
|
||||
QTextStream stream(&file);
|
||||
stream.setCodec("utf-8");
|
||||
stream<<to_json();
|
||||
file.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
file.open(QIODevice::ReadOnly);
|
||||
QTextStream stream(&file);
|
||||
stream.setCodec("utf-8");
|
||||
mystring json_str = stream.readAll();
|
||||
to_class(json_str);
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
// 把配置写入json文件
|
||||
void mycfg::save()
|
||||
{
|
||||
QFile file;
|
||||
file.setFileName(CFG_FILE_NAME);
|
||||
if(file.exists())
|
||||
{
|
||||
if(file.remove()!=true)
|
||||
qWarning()<<"remove file "<<file.fileName()<<"err"<<endl;
|
||||
}
|
||||
file.open(QIODevice::ReadWrite);
|
||||
QTextStream stream(&file);
|
||||
stream.setCodec("utf-8");
|
||||
stream<<to_json();
|
||||
file.flush();
|
||||
file.close();
|
||||
system((char *)"sync");
|
||||
}
|
||||
|
||||
|
||||
// 把文件保存到配置路径下
|
||||
bool mycfg::save_file(mystring name,myarray data){
|
||||
QFile file;
|
||||
file.setFileName(CFG_PATH+name);
|
||||
if(file.exists())
|
||||
{
|
||||
if(file.remove()!=true){
|
||||
qWarning()<<"remove file "<<file.fileName()<<"err"<<endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
file.open(QIODevice::ReadWrite);
|
||||
file.write(data);
|
||||
file.flush();
|
||||
file.close();
|
||||
system((char *)"sync");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
mycfg g_syscfg;
|
||||
|
||||
mycfg *syscfg(){
|
||||
return &g_syscfg;
|
||||
// 更新生产信息
|
||||
void mycfg::updata_produc_info(myarray data)
|
||||
{
|
||||
production_info.clear();
|
||||
for(int i=0;i<data.size();i++){
|
||||
production_info.append(data[i]);
|
||||
}
|
||||
}
|
||||
void mycfg::updata_produc_info(QList<int> data)
|
||||
{
|
||||
production_info.clear();
|
||||
for(int i=0;i<data.size();i++){
|
||||
production_info.append(data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
mycfg *g_syscfg;
|
||||
|
||||
mycfg *syscfg(){
|
||||
if(g_syscfg==nullptr){
|
||||
g_syscfg=new mycfg();
|
||||
}
|
||||
return g_syscfg;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user