Qt之操作系统环境 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:Userswangl-dAppDataLocal" "LIB=D:Program FilesMicrosoft Visual Studio 10.0VCLIB;D:Program FilesMicrosoft Visual Studio 10.0VCATLMFCLIB;C:Program Files (x86)Microsoft SDKsWindowsv7.0Alib;" 
Qt之操作系统环境 qt操作系统
"LOGONSERVER=\GLODON-DC01" "ASL.LOG=Destination=file" "PATH=D:QtQt5.1.15.1.1msvc2010lib;D:WorksGAEA-PUBLICGJHtrunkImportsGlodonResourceGlodonlibDebugX86;D:WorksGAEA-PUBLICGJHtrunkImportsGlodonResourceThirdPartRichTextlibDebugX86;D:WorksGAEA-PUBLICGJHtrunkImportsGlodonResourceThirdPartquaziplibDebugX86;D:WorksGAEA-PUBLICGJHtrunkImportsGlodonResourceGlodonlibDebugX86;D:WorksGAEA-PUBLICGJHtrunkImportsGlodonResourceThirdPartRichTextlibDebugX86;D:WorksGAEA-PUBLICGJHtrunkImportsGlodonResourceThirdPartquaziplibDebugX86;D:WorksGAEA-PUBLICGJHtrunkImportsGlodonResourceThirdPartVLDlibWin32;D:WorksGAEA-PUBLICGGMtrunklibVectorDrawEditorlibx86;D:QtQt5.1.15.1.1msvc2010bin;C:Program Files (x86)Microsoft F#v4.0;D:Program FilesMicrosoft Visual Studio 10.0VSTSDBDeploy;D:Program FilesMicrosoft Visual Studio 10.0Common7IDE;D:Program FilesMicrosoft Visual Studio 10.0VCBIN;D:Program FilesMicrosoft Visual Studio 10.0Common7Tools;C:WindowsMicrosoft.NETFrameworkv4.0.30319;C:WindowsMicrosoft.NETFrameworkv3.5;D:Program FilesMicrosoft Visual Studio 10.0VCVCPackages;C:Program Files (x8 6)HTML Help Workshop;C:Program Files (x86)HTML Help Workshop;D:Program FilesMicrosoft Visual Studio 10.0Team ToolsPerformance Tools;C:Program Files (x86)Microsoft SDKsWindowsv7.0AbinNETFX 4.0 Tools;C:Program Files (x86)Microsoft SDKsWindowsv7.0Abin;C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;C:Program Files (x86)IntelOpenCL SDK3.0binx86;C:Program Files (x86)IntelOpenCL SDK3.0binx64;D:Program FilesTortoiseSVNbin;C:Program Files (x86)Microsoft SQL Server100ToolsBinn;C:Program FilesMicrosoft SQL Server100ToolsBinn;C:Program FilesMicrosoft SQL Server100DTSBinn;D:WorksGAEA-PUBLICGJHtrunkImportsGlodonResourceThirdPartQtitanlib;D:WorksGAEA-PUBLICGJHtrunkImportsGlodonResourceThirdPartVLDbinWin32;D:QtQt5.1.15.1.1msvc2010bin;D:GlodonGFY2.0_newControlsGrandResourceLib;D:GlodonGFY2.0_newControlsGAEAResourceGCLBpl" "COMMONPROGRAMFILES(X86)=C:Program Files (x86)Common Files" "USERDOMAIN=GRANDSOFT" "FRAMEWORKVERSION32=v4.0.30319" "QTDIR=D:QtQt5.1.15.1.1msvc2010" "WINDOWS_TRACING_LOGFILE=C:BVTBinTestsinstallpackagecsilogfile.log" "FRAMEWORKDIR=C:WindowsMicrosoft.NETFramework" "PROGRAMW6432=C:Program Files" "TMP=C:Userswangl-dAppDataLocalTemp"
"QTITANDIR=D:WorksGAEA-PUBLICGJHtrunkImportsGlodonResourceThirdPartQtitan"
"FRAMEWORKDIR32=C:WindowsMicrosoft.NETFramework" "USERNAME=wangl-d" "FP_NO_HOST_CHECK=NO" "TEMP=C:Userswangl-dAppDataLocalTemp" "FRAMEWORKVERSION=v4.0.30319" "VCINSTALLDIR=D:Program FilesMicrosoft Visual Studio 10.0VC" "PROMPT=$P$G"
"VSEDEFLOGDIR=C:ProgramDataMcAfeeDesktopProtection" "HOMEPATH=Userswangl-d" "WINDOWS_TRACING_FLAGS=3" "GLDRS=D:WorksGAEA-PUBLICGJHtrunkImportsGlodonResource" "NUMBER_OF_PROCESSORS=4"
"VSINSTALLDIR=D:Program FilesMicrosoft Visual Studio 10.0"
"COMSPEC=C:Windowssystem32cmd.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 SDKsWindowsv7.0A" "HOMEDRIVE=C:" "DEVENVDIR=D:Program FilesMicrosoft Visual Studio 10.0Common7IDE"
"COMPUTERNAME=WANGL-D-PC"
"PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC" "APPDATA=C:Userswangl-dAppDataRoaming" "PROGRAMDATA=C:ProgramData" "PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 58 Stepping 9, GenuineIntel" "PUBLIC=C:UsersPublic" "COMMONPROGRAMFILES=C:Program Files (x86)Common Files" "OS=Windows_NT" "FRAMEWORK35VERSION=v3.5" "DEFLOGDIR=C:ProgramDataMcAfeeDesktopProtection" "LIBPATH=C:WindowsMicrosoft.NETFrameworkv4.0.30319;C:WindowsMicrosoft.NETFrameworkv3.5;D:Program FilesMicrosoft Visual Studio 10.0VCLIB;D:Program FilesMicrosoft Visual Studio 10.0VCATLMFCLIB;"
"BDSCOMMONDIR=C:UsersPublicDocumentsRAD Studio5.0" "VS100COMNTOOLS=D:Program FilesMicrosoft Visual Studio 10.0Common7Tools" "COMMONPROGRAMW6432=C:Program FilesCommon Files" "USERPROFILE=C:Userswangl-d" "WINDIR=C:Windows" "PROGRAMFILES(X86)=C:Program Files (x86)" "PSMODULEPATH=C:Windowssystem32WindowsPowerShellv1.0Modules" "PROCESSOR_ARCHITECTURE=x86" "GRS=D:GlodonGFY2.0_newControlsGrandResource"
"PROCESSOR_ARCHITEW6432=AMD64"
"SESSIONNAME=Console" "SYSTEMROOT=C:Windows" "USERDNSDOMAIN=GRANDSOFT.COM.CN"
"ALLUSERSPROFILE=C:ProgramData"
"INCLUDE=D:Program FilesMicrosoft Visual Studio 10.0VCINCLUDE;D:Program FilesMicrosoft Visual Studio 10.0VCATLMFCINCLUDE;C:Program Files (x86)Microsoft SDKsWindowsv7.0Ainclude;"
以上环境变量具体都是什么意思,我就不解释了,见名知义,大家肯定都比我聪明,O(∩_∩)O~。。。
更多参考:
注:技术在于交流、沟通,转载请注明出处并保持作品的完整性。作者:╰☆奋斗ing❤孩子`原文:http://blog.sina.com.cn/s/blog_a6fb6cc90102uy9k.html。

  

爱华网本文地址 » http://www.aihuau.com/a/25101015/261816.html

更多阅读

英雄联盟内置QT怎么用 英雄联盟内置qt修复

英雄联盟内置QT怎么用——简介最近的英雄联盟更新了QT内置语音,不需要其他软件就可以开黑语音了,那怎么用呢?注意目前只有艾欧尼亚电信区和守望之海电信区有这个功能,其他大区需要等官网更新。英雄联盟内置QT怎么用——方法/步骤

风水之水法 环境风水吉凶水法一

穴虽在山,祸福在水。所以点穴之法,以水定之。山如妇,水如夫,妇从夫贵。如中原万里无山,英雄迭出,何故其贵在水。故曰有山取山断,无山取水断。夫石为山之骨,土为山之肉,水为山之血脉,草木为山之皮毛,皆血脉之贯通也。只用天干,不用地支,水法皆然。

转载 吴劲松操作系统 吴劲松新浪微博

原文地址:吴劲松操作系统作者:春之歌吴劲松操作系统我的黄线系统大家已经非常熟悉了,很多同学会发现一个现象,就是黄线家数更多的是提示大波段用的,比如基本能提前一至两周预测阶段的头部或底部,但在股价运行期间的指导意义不大。其实,我

用QMediaPlayer实现MP3音乐播放器(C++Qt) qt实现音乐播放器

这个国庆又没闲着,利用中间这几天实现了一个简易的MP3音乐播放器,其音乐播放的核心功能是采用QtQMultimedia中的QMediaPlayer控件(网上使用Phonon框架的较多)。在实现的过程中,界面使用QtDesigner设计,这在很大程度上减小了C++代码量。

转载unix系统病毒与安全 unix操作系统 安全性

系统安全之谈谈Linux和UNIX下的病毒作者:smtk 来源:赛迪网安全社区不久以前,很多系统管理员还信誓旦旦的表示,Linux和其他基于UNIX的平台对于病毒和蠕虫事实上是无懈可击的。我不知道为什么他们对自己的威胁分析这么自信,特别是从第一

声明:《Qt之操作系统环境 qt操作系统》为网友辠快感分享!如侵犯到您的合法权益请联系我们删除