1. 运行设备上有T_ROOT这个环境变量,获取环境变量方法如下:
QString path = QProcessEnvironment::systemEnvironment().value("T_ROOT"); //获取名为T_ROOT的环境变量
path.replace(QRegExp("\\\\"),"/"); //将‘\’替换成‘/’
qDebug() << "T_ROOT path value %s"
QProcess process;
process.start(str); //使用输出的变量值
bool flag = process.waitForFinished();
2. 通过QSetting保存变量
QSettings *configIni = new QSettings("./conf/conf.ini", QSettings::IniFormat);
QString Result = configIni->value("/QTDIR/PATH").toString();
if(Result == ""){
configIni->setValue("/QTDIR/PATH", "C:/Qt/Qt5.12.0/5.12.0/msvc2015_64");
Result = "C:/Qt/Qt5.12.0/5.12.0/msvc2015_64";
}
w.setCommand(configIni->value("/QTDIR/PATH").toString());//写入到类成员
本文参考链接:https://blog.csdn.net/github_35960067/article/details/84971228