1.头文件中 定义全局变量
#ifndef Z3_GVARS_H
#define Z3_GVARS_H
#include <QString>
class Z3_GVARS {
public :
static QString JSON_FILE_NAME ;
static QString SERVER_IP ;
static int SERVER_PORT;
static void initConfig();
};
#endif // ! Z3_GVARS_H
2.在cpp中初始化全局变量,定义函数:
#include "Z3_GVARS.h"
#include <QString>
QString Z3_GVARS::JSON_FILE_NAME = "C:\\temp\\request.json";
QString Z3_GVARS::SERVER_IP = "127.0.0.1";
int Z3_GVARS::SERVER_PORT = 9998;
void Z3_GVARS::initConfig() {
Z3_GVARS::JSON_FILE_NAME = "C:\\temp\\request.json";
Z3_GVARS::SERVER_IP = "127.0.0.1";
Z3_GVARS::SERVER_PORT = 9999;
};
3.在dll加载入口,运行初始化函数,初始化变量
#include "Z3_GVARS.h"
class Z3_GVARS;
int ZW3DTCInit() {
//初始化静态
Z3_GVARS::initConfig();
。。。。
}
标签:初始化,QT,GVARS,SERVER,static,QString,全局变量,Z3 From: https://www.cnblogs.com/PLM-Teamcenter/p/18607110