系统环境变量还是挺重要的,除了QStandardPaths(感觉都是文档类型的变量,QT4使用QDesktopServices),更有QProcessEnvironment(都是真正的系统变量):
QString strWindows = QProcessEnvironment::systemEnvironment().value("windir"); qDebug() << strWindows; qDebug() << QProcessEnvironment::systemEnvironment().value("ALLUSERSPROFILE"); QStringList environmentList = QProcess::systemEnvironment(); foreach (QString environment, environmentList ) { qDebug() << environment; }
结果如下:
"ALLUSERSPROFILE=C:\ProgramData"
"APPDATA=C:\Users\kk\AppData\Roaming"
"CommonProgramFiles=C:\Program Files (x86)\Common Files"
"CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files"
"CommonProgramW6432=C:\Program Files\Common Files"
"COMPUTERNAME=My-PC2"
"ComSpec=C:\Windows\system32\cmd.exe"
"FP_NO_HOST_CHECK=NO"
"GIT_SSH=C:\Program Files\TortoiseGit\bin\TortoiseGitPlink.exe"
"HOME=C:\Users\kk"
"HOMEDRIVE=C:"
"HOMEPATH=\Users\kk"
"LOCALAPPDATA=C:\Users\kk\AppData\Local"
"LOGONSERVER=\\BURO"
"NUMBER_OF_PROCESSORS=4"
"OS=Windows_NT"
"PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC"
"PROCESSOR_ARCHITECTURE=x86"
"PROCESSOR_ARCHITEW6432=AMD64"
"PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 60 Stepping 3, GenuineIntel"
"PROCESSOR_LEVEL=6"
"PROCESSOR_REVISION=3c03"
"ProgramData=C:\ProgramData"
"ProgramFiles=C:\Program Files (x86)"
"ProgramFiles(x86)=C:\Program Files (x86)"
"ProgramW6432=C:\Program Files"
"PSModulePath=C:\Windows\system32\WindowsPowerShell\v1.0\Modules\"
"PUBLIC=C:\Users\Public"
"QMAKESPEC=C:\Qt\Qt5.3.2_static\mkspecs\win32-g++"
"QTDIR=C:\Qt\Qt5.3.2\5.3\msvc2010_opengl"
"SESSIONNAME=Console"
"SVN_SSH=C:\Program Files\TortoiseGit\bin\TortoiseGitPlink.exe"
"SystemDrive=C:"
"SystemRoot=C:\Windows"
"TEMP=C:\Users\kk\AppData\Local\Temp"
"TMP=C:\Users\kk\AppData\Local\Temp"
"USERDNSDOMAIN=EDIPUB.COM"
"USERDOMAIN=EDIPUB"
"USERNAME=kk"
"USERPROFILE=C:\Users\kk"
"VBOX_MSI_INSTALL_PATH=C:\Program Files\Oracle\VirtualBox\"
"VisualStudioDir=C:\Users\kk\Documents\Visual Studio 2010"
"VS100COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\"
"VS110COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\"
"VS80COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 8\Common7\Tools\"
"VS90COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools\"
"windir=C:\Windows"
"windows_tracing_flags=3"
"windows_tracing_logfile=C:\BVTBin\Tests\installpackage\csilogfile.log"
"__COMPAT_LAYER=ElevateCreateProcess"
"PATH=C:\Qt\Qt5.3.2\5.3\msvc2010_opengl\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\TortoiseGit\bin;C:\Program Files (x86)\Git\cmd;C:\Qt\Qt5.3.2_min\Tools\mingw482_32\bin;C:\Qt\Qt5.3.2_min\5.3\mingw482_32\bin;C:\Python27;C:\Perl\bin;c:\Perl;C:\Qt\Qt5.3.2_min\Tools\mingw482_32\bin;C:\Program Files (x86)\Microsoft Visual Studio 10.0\;C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin"