QProcessEnvironment 类保持可以被传递给程序的环境变量。 更多...
头: | #include <QProcessEnvironment> |
CMake: |
find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core) |
qmake: | QT += core |
注意: 此类的所有函数 可重入 .
enum | Initialization { InheritFromParent } |
QProcessEnvironment () | |
QProcessEnvironment (QProcessEnvironment::Initialization) | |
QProcessEnvironment (const QProcessEnvironment & other ) | |
~QProcessEnvironment () | |
void | clear () |
bool | contains (const QString & name ) const |
bool | inheritsFromParent () const |
void | insert (const QString & name , const QString & value ) |
void | insert (const QProcessEnvironment & e ) |
bool | isEmpty () const |
QStringList | keys () const |
void | remove (const QString & name ) |
void | swap (QProcessEnvironment & other ) |
QStringList | toStringList () const |
QString | value (const QString & name , const QString & defaultValue = QString()) const |
bool | operator!= (const QProcessEnvironment & other ) const |
QProcessEnvironment & | operator= (const QProcessEnvironment & other ) |
bool | operator== (const QProcessEnvironment & other ) const |
QProcessEnvironment | systemEnvironment () |
A process's environment is composed of a set of key=value pairs known as environment variables. The QProcessEnvironment class wraps that concept and allows easy manipulation of those variables. It's meant to be used along with QProcess , to set the environment for child processes. It cannot be used to change the current process's environment.
The environment of the calling process can be obtained using QProcessEnvironment::systemEnvironment ().
On Unix systems, the variable names are case-sensitive. Note that the Unix environment allows both variable names and contents to contain arbitrary binary data (except for the NUL character). QProcessEnvironment will preserve such variables, but does not support manipulating variables whose names or values cannot be encoded by the current locale settings (see QString::toLocal8Bit ).
On Windows, the variable names are case-insensitive, but case-preserving. QProcessEnvironment behaves accordingly.
另请参阅 QProcess , QProcess::systemEnvironment (),和 QProcess::setProcessEnvironment ().
[since 6.3]
enum QProcessEnvironment::
Initialization
此枚举包含用于消除构造函数歧义的令牌。
常量 | 值 | 描述 |
---|---|---|
QProcessEnvironment::InheritFromParent
|
0
|
A QProcessEnvironment will be created that, when set on a QProcess , causes it to inherit variables from its parent. |
This enum was introduced or modified in Qt 6.3.
Creates a new QProcessEnvironment object. This constructor creates an empty environment. If set on a QProcess , this will cause the current environment variables to be removed (except for PATH and SystemRoot on Windows).
[since 6.3]
QProcessEnvironment::
QProcessEnvironment
(
QProcessEnvironment::Initialization
)
Creates an object that when set on QProcess will cause it to be executed with environment variables inherited from its parent process.
注意: The created object does not store any environment variables by itself, it just indicates to QProcess to arrange for inheriting the environment at the time when the new process is started. Adding any environment variables to the created object will disable inheritance of the environment and result in an environment containing only the added environment variables.
If a modified version of the parent environment is wanted, start with the return value of
systemEnvironment()
and modify that (but note that changes to the parent process's environment after that is created won't be reflected in the modified environment).
该函数在 Qt 6.3 引入。
另请参阅 inheritsFromParent () 和 systemEnvironment ().
Creates a QProcessEnvironment object that is a copy of other .
Frees the resources associated with this QProcessEnvironment 对象。
Removes all key=value pairs from this QProcessEnvironment object, making it empty.
If the environment was constructed using
QProcessEnvironment::InheritFromParent
it remains unchanged.
另请参阅 isEmpty () 和 systemEnvironment ().
返回
true
若环境变量名
name
被找到在此
QProcessEnvironment
对象。
[since 6.3]
bool
QProcessEnvironment::
inheritsFromParent
() const
返回
true
若此
QProcessEnvironment
的构造是使用
QProcessEnvironment::InheritFromParent
.
该函数在 Qt 6.3 引入。
另请参阅 isEmpty ().
插入环境变量按名称 name 和内容 value 到此 QProcessEnvironment 对象。若变量已经存在,以新值替换它。
在大多数系统,插入没有内容的变量对应用程序与根本没有设置变量的效果相同。不管怎样,为保证不存在不兼容,要移除变量请使用 remove () 函数。
另请参阅 contains (), remove (),和 value ().
这是重载函数。
插入内容为 e 在此 QProcessEnvironment 对象。在此对象中的变量还存在于 e 会被覆写。
返回
true
若此
QProcessEnvironment
对象为空:没有设置 "键=值" 对。
此方法也返回
true
若对象的构造是使用
QProcessEnvironment::InheritFromParent
.
另请参阅 clear (), systemEnvironment (), insert (),和 inheritsFromParent ().
返回包含所有变量名称的列表在此 QProcessEnvironment 对象。
返回列表为空,若对象的构造是使用
QProcessEnvironment::InheritFromParent
.
移除环境变量标识通过 name 从此 QProcessEnvironment 对象。若变量之前不存在,什么都不发生。
另请参阅 contains (), insert (),和 value ().
交换此进程环境实例与 other 。此函数非常快且从不失败。
[static]
QProcessEnvironment
QProcessEnvironment::
systemEnvironment
()
The systemEnvironment function returns the environment of the calling process.
它被返回作为
QProcessEnvironment
. This function does not cache the system environment. Therefore, it's possible to obtain an updated version of the environment if low-level C library functions like
setenv
or
putenv
有被调用。
However, note that repeated calls to this function will recreate the QProcessEnvironment object, which is a non-trivial operation.
另请参阅 QProcess::systemEnvironment ().
转换此 QProcessEnvironment object into a list of strings, one for each environment variable that is set. The environment variable's name and its value are separated by an equal character ('=').
The QStringList contents returned by this function are suitable for presentation. Use with the QProcess::setEnvironment function is not recommended due to potential encoding problems under Unix, and worse performance.
另请参阅 systemEnvironment (), QProcess::systemEnvironment (),和 QProcess::setProcessEnvironment ().
搜索此 QProcessEnvironment object for a variable identified by name and returns its value. If the variable is not found in this object, then defaultValue 被返回取而代之。
另请参阅 contains (), insert (),和 remove ().
返回
true
若此和
other
QProcessEnvironment
对象不同。
另请参阅 operator== ().
拷贝内容从 other QProcessEnvironment 对象到此对象。
返回
true
若此和
other
QProcessEnvironment
对象相等。
Two QProcessEnvironment objects are considered equal if they have the same set of key=value pairs. The comparison of keys is done case-sensitive on platforms where the environment is case-sensitive.
另请参阅 operator!= () 和 contains ().