加载中…
个人资料
一去二三里
一去二三里
  • 博客等级:
  • 博客积分:0
  • 博客访问:2,322,840
  • 关注人气:898
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
相关博文
推荐博文
谁看过这篇博文
加载中…
正文 字体大小:

Qt之操作系统环境

(2014-08-25 14:41:45)
标签:

qt

qprocess

qprocesssystemenvi

systemenvironment()

分类: Qt
    Qt中操作系统环境,官方解释如下:

QStringList QProcess::systemEnvironment() [static]

Returns the environment of the calling process as a list of key=value pairs. Example:

QStringList environment = QProcess::systemEnvironment();
// environment = {"PATH=/usr/bin:/usr/local/bin",
//                "USER=greg", "HOME=/home/gr
    返回的结果以类似键、值的形式存储。
    举例:获取系统盘下面的AppData目录

QString appdataPath()
{
    QStringList environmentList = QProcess::systemEnvironment();
    QString appPath("");
    foreach (QString environment, environmentList )
    {
        if (environment.startsWith("APPDATA=", Qt::CaseInsensitive))
        {
            appPath = environment.mid(QString("APPDATA=").length());
            break;
        }
    }
    return appPath ;
}     

    更简单的可以通过:QString value = QProcessEnvironment::systemEnvironment().value("APPDATA");来获取相应的键对应的值。
    这样就可以像其它应用程序一样在自己的目录下放置自己所需的资源、配置文件。。。更多操作可参考:QProcess中setEnvironment、setProcessEnvironment等函数!

    如果不知道里面都有什么键值,最简单的方法就是全部输出,查看是否存在自己想要获取的内容!

QStringList environmentList = QProcess::systemEnvironment();
foreach (QString environment, environmentList )
{
        qDebug() << environment;
}
    测试结果如下:

"LOCALAPPDATA=C:\Users\wangl-d\AppData\Local" 

"LIB=D:\Program Files\Microsoft Visual Studio 10.0\VC\LIB;D:\Program Files\Microsoft Visual Studio 10.0\VC\ATLMFC\LIB;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\lib;" 
"LOGONSERVER=\\GLODON-DC01" "ASL.LOG=Destination=file" "PATH=D:\Qt\Qt5.1.1\5.1.1\msvc2010\lib;D:\Works\GAEA-PUBLIC\GJH\trunk\Imports\GlodonResource\Glodon\lib\Debug\X86;D:\Works\GAEA-PUBLIC\GJH\trunk\Imports\GlodonResource\ThirdPart\RichText\lib\Debug\X86;D:\Works\GAEA-PUBLIC\GJH\trunk\Imports\GlodonResource\ThirdPart\quazip\lib\Debug\X86;D:\Works\GAEA-PUBLIC\GJH\trunk\Imports\GlodonResource\Glodon\lib\Debug\X86;D:\Works\GAEA-PUBLIC\GJH\trunk\Imports\GlodonResource\ThirdPart\RichText\lib\Debug\X86;D:\Works\GAEA-PUBLIC\GJH\trunk\Imports\GlodonResource\ThirdPart\quazip\lib\Debug\X86;D:\Works\GAEA-PUBLIC\GJH\trunk\Imports\GlodonResource\ThirdPart\VLD\lib\Win32;D:\Works\GAEA-PUBLIC\GGM\trunk\lib\VectorDrawEditor\lib\x86;D:\Qt\Qt5.1.1\5.1.1\msvc2010\bin;C:\Program Files (x86)\Microsoft F#\v4.0\;D:\Program Files\Microsoft Visual Studio 10.0\VSTSDB\Deploy;D:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\;D:\Program Files\Microsoft Visual Studio 10.0\VC\BIN;D:\Program Files\Microsoft Visual Studio 10.0\Common7\Tools;C:\Windows\Microsoft.NET\Framework\v4.0.30319;C:\Windows\Microsoft.NET\Framework\v3.5;D:\Program Files\Microsoft Visual Studio 10.0\VC\VCPackages;C:\Program Files (x86)\HTML Help Workshop;C:\Program Files (x86)\HTML Help Workshop;D:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Performance Tools;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\OpenCL SDK\3.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\3.0\bin\x64;D:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;D:\Works\GAEA-PUBLIC\GJH\trunk\Imports\GlodonResource\ThirdPart\Qtitan\lib;D:\Works\GAEA-PUBLIC\GJH\trunk\Imports\GlodonResource\ThirdPart\VLD\bin\Win32;D:\Qt\Qt5.1.1\5.1.1\msvc2010\bin;D:\Glodon\GFY2.0_new\Controls\GrandResource\Lib;D:\Glodon\GFY2.0_new\Controls\GAEAResource\GCL\Bpl" "COMMONPROGRAMFILES(X86)=C:\Program Files (x86)\Common Files" "USERDOMAIN=GRANDSOFT" "FRAMEWORKVERSION32=v4.0.30319" "QTDIR=D:\Qt\Qt5.1.1\5.1.1\msvc2010" "WINDOWS_TRACING_LOGFILE=C:\BVTBin\Tests\installpackage\csilogfile.log" "FRAMEWORKDIR=C:\Windows\Microsoft.NET\Framework\" "PROGRAMW6432=C:\Program Files" "TMP=C:\Users\wangl-d\AppData\Local\Temp"
"QTITANDIR=D:\Works\GAEA-PUBLIC\GJH\trunk\Imports\GlodonResource\ThirdPart\Qtitan"
"FRAMEWORKDIR32=C:\Windows\Microsoft.NET\Framework\" "USERNAME=wangl-d" "FP_NO_HOST_CHECK=NO" "TEMP=C:\Users\wangl-d\AppData\Local\Temp" "FRAMEWORKVERSION=v4.0.30319" "VCINSTALLDIR=D:\Program Files\Microsoft Visual Studio 10.0\VC\" "PROMPT=$P$G"
"VSEDEFLOGDIR=C:\ProgramData\McAfee\DesktopProtection" "HOMEPATH=\Users\wangl-d" "WINDOWS_TRACING_FLAGS=3" "GLDRS=D:\Works\GAEA-PUBLIC\GJH\trunk\Imports\GlodonResource" "NUMBER_OF_PROCESSORS=4"
"VSINSTALLDIR=D:\Program Files\Microsoft Visual Studio 10.0\"
"COMSPEC=C:\Windows\system32\cmd.exe"
"PROGRAMFILES=C:\Program Files (x86)" "SYSTEMDRIVE=C:" "FSHARPINSTALLDIR=C:\Program Files (x86)\Microsoft F#\v4.0\"
"PROCESSOR_REVISION=3a09"
"PROCESSOR_LEVEL=6"
"WINDOWSSDKDIR=C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\" "HOMEDRIVE=C:" "DEVENVDIR=D:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\"
"COMPUTERNAME=WANGL-D-PC"
"PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC" "APPDATA=C:\Users\wangl-d\AppData\Roaming" "PROGRAMDATA=C:\ProgramData" "PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 58 Stepping 9, GenuineIntel" "PUBLIC=C:\Users\Public" "COMMONPROGRAMFILES=C:\Program Files (x86)\Common Files" "OS=Windows_NT" "FRAMEWORK35VERSION=v3.5" "DEFLOGDIR=C:\ProgramData\McAfee\DesktopProtection" "LIBPATH=C:\Windows\Microsoft.NET\Framework\v4.0.30319;C:\Windows\Microsoft.NET\Framework\v3.5;D:\Program Files\Microsoft Visual Studio 10.0\VC\LIB;D:\Program Files\Microsoft Visual Studio 10.0\VC\ATLMFC\LIB;"
"BDSCOMMONDIR=C:\Users\Public\Documents\RAD Studio\5.0" "VS100COMNTOOLS=D:\Program Files\Microsoft Visual Studio 10.0\Common7\Tools\" "COMMONPROGRAMW6432=C:\Program Files\Common Files" "USERPROFILE=C:\Users\wangl-d" "WINDIR=C:\Windows" "PROGRAMFILES(X86)=C:\Program Files (x86)" "PSMODULEPATH=C:\Windows\system32\WindowsPowerShell\v1.0\Modules\" "PROCESSOR_ARCHITECTURE=x86" "GRS=D:\Glodon\GFY2.0_new\Controls\GrandResource"
"PROCESSOR_ARCHITEW6432=AMD64"
"SESSIONNAME=Console" "SYSTEMROOT=C:\Windows" "USERDNSDOMAIN=GRANDSOFT.COM.CN"
"ALLUSERSPROFILE=C:\ProgramData"
"INCLUDE=D:\Program Files\Microsoft Visual Studio 10.0\VC\INCLUDE;D:\Program Files\Microsoft Visual Studio 10.0\VC\ATLMFC\INCLUDE;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include;"
    以上环境变量具体都是什么意思,我就不解释了,见名知义,大家肯定都比我聪明,O(∩_∩)O~。。。

更多参考:

注:
    技术在于交流、沟通,转载请注明出处并保持作品的完整性。

0

阅读 评论 收藏 转载 喜欢 打印举报/Report
  • 评论加载中,请稍候...
发评论

    发评论

    以上网友发言只代表其个人观点,不代表新浪网的观点或立场。

      

    新浪BLOG意见反馈留言板 电话:4000520066 提示音后按1键(按当地市话标准计费) 欢迎批评指正

    新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 会员注册 | 产品答疑

    新浪公司 版权所有