PySide6.QtCore.QProcessEnvironment¶
- class QProcessEnvironment¶
The
QProcessEnvironmentclass holds the environment variables that can be passed to a program.Details
A process’s environment is composed of a set of key=value pairs known as environment variables. The
QProcessEnvironmentclass wraps that concept and allows easy manipulation of those variables. It’s meant to be used along withQProcess, 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
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).
QProcessEnvironmentwill preserve such variables, but does not support manipulating variables whose names or values cannot be encoded by the current locale settings (seetoLocal8Bit).On Windows, the variable names are case-insensitive, but case-preserving.
QProcessEnvironmentbehaves accordingly.Synopsis¶
Methods¶
def
__init__()def
clear()def
contains()def
insert()def
isEmpty()def
keys()def
__ne__()def
__eq__()def
remove()def
swap()def
toStringList()def
value()
Static functions¶
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
- class Initialization¶
This enum contains a token that is used to disambiguate constructors.
Constant
Description
QProcessEnvironment.Initialization.InheritFromParent
A
QProcessEnvironmentwill be created that, when set on aQProcess, causes it to inherit variables from its parent.Added in version 6.3.
- __init__()¶
Creates a new
QProcessEnvironmentobject. This constructor creates an empty environment. If set on aQProcess, this will cause the current environment variables to be removed (except for PATH and SystemRoot on Windows).- __init__(arg__1)
- Parameters:
arg__1 –
Initialization
Creates an object that when set on
QProcesswill cause it to be executed with environment variables inherited from its parent process.Note
The created object does not store any environment variables by itself, it just indicates to
QProcessto 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).See also
- __init__(other)
- Parameters:
other –
QProcessEnvironment
Creates a
QProcessEnvironmentobject that is a copy ofother.- clear()¶
Removes all key=value pairs from this
QProcessEnvironmentobject, making it empty.If the environment was constructed using
QProcessEnvironment::InheritFromParentit remains unchanged.See also
- contains(name)¶
- Parameters:
name – str
- Return type:
bool
Returns
trueif the environment variable of namenameis found in thisQProcessEnvironmentobject.- inheritsFromParent()¶
- Return type:
bool
Returns
trueif thisQProcessEnvironmentwas constructed usingQProcessEnvironment::InheritFromParent.See also
- insert(e)¶
- Parameters:
Inserts the contents of
ein thisQProcessEnvironmentobject. Variables in this object that also exist inewill be overwritten.- insert(name, value)
- Parameters:
name – str
value – str
Inserts the environment variable of name
nameand contentsvalueinto thisQProcessEnvironmentobject. If that variable already existed, it is replaced by the new value.On most systems, inserting a variable with no contents will have the same effect for applications as if the variable had not been set at all. However, to guarantee that there are no incompatibilities, to remove a variable, please use the
remove()function.See also
- isEmpty()¶
- Return type:
bool
Returns
trueif thisQProcessEnvironmentobject is empty: that is there are no key=value pairs set.This method also returns
truefor objects that were constructed usingQProcessEnvironment::InheritFromParent.- keys()¶
- Return type:
list of strings
Returns a list containing all the variable names in this
QProcessEnvironmentobject.The returned list is empty for objects constructed using
QProcessEnvironment::InheritFromParent.- __ne__(rhs)¶
- Parameters:
rhs –
QProcessEnvironment- Return type:
bool
Returns
trueif the process environment objectslhsandrhsare different.See also
operator==()- __eq__(rhs)¶
- Parameters:
rhs –
QProcessEnvironment- Return type:
bool
Returns
trueif the process environment objectslhsandrhsare equal.Two
QProcessEnvironmentobjects 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.See also
operator!=()contains()- remove(name)¶
- Parameters:
name – str
Removes the environment variable identified by
namefrom thisQProcessEnvironmentobject. If that variable did not exist before, nothing happens.See also
- swap(other)¶
- Parameters:
other –
QProcessEnvironment
Swaps this process environment instance with
other. This operation is very fast and never fails.- static systemEnvironment()¶
- Return type:
The systemEnvironment function returns the environment of the calling process.
It is returned as a
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 likesetenvorputenvhave been called.However, note that repeated calls to this function will recreate the
QProcessEnvironmentobject, which is a non-trivial operation.See also
- toStringList()¶
- Return type:
list of strings
Converts this
QProcessEnvironmentobject 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
QStringListcontents 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.- value(name[, defaultValue=""])¶
- Parameters:
name – str
defaultValue – str
- Return type:
str
Searches this
QProcessEnvironmentobject for a variable identified bynameand returns its value. If the variable is not found in this object, thendefaultValueis returned instead.See also