QProcessEnvironment#

The QProcessEnvironment class holds the environment variables that can be passed to a program. More

New in version 4.6.

Synopsis#

Functions#

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

Detailed Description#

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 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 toLocal8Bit ).

On Windows, the variable names are case-insensitive, but case-preserving. QProcessEnvironment behaves accordingly.

class PySide6.QtCore.QProcessEnvironment#

PySide6.QtCore.QProcessEnvironment(arg__1)

PySide6.QtCore.QProcessEnvironment(other)

Parameters:

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).

Creates an object that when set on QProcess will 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 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).

Creates a QProcessEnvironment object that is a copy of other.

PySide6.QtCore.QProcessEnvironment.Initialization#

This enum contains a token that is used to disambiguate constructors.

Constant

Description

QProcessEnvironment.InheritFromParent

A QProcessEnvironment will be created that, when set on a QProcess , causes it to inherit variables from its parent.

New in version 6.3.

PySide6.QtCore.QProcessEnvironment.clear()#

Removes all key=value pairs from this QProcessEnvironment object, making it empty.

If the environment was constructed using QProcessEnvironment::InheritFromParent it remains unchanged.

PySide6.QtCore.QProcessEnvironment.contains(name)#
Parameters:

name – str

Return type:

bool

Returns true if the environment variable of name name is found in this QProcessEnvironment object.

See also

insert() value()

PySide6.QtCore.QProcessEnvironment.inheritsFromParent()#
Return type:

bool

Returns true if this QProcessEnvironment was constructed using QProcessEnvironment::InheritFromParent.

See also

isEmpty()

PySide6.QtCore.QProcessEnvironment.insert(e)#
Parameters:

ePySide6.QtCore.QProcessEnvironment

This is an overloaded function.

Inserts the contents of e in this QProcessEnvironment object. Variables in this object that also exist in e will be overwritten.

PySide6.QtCore.QProcessEnvironment.insert(name, value)
Parameters:
  • name – str

  • value – str

Inserts the environment variable of name name and contents value into this QProcessEnvironment object. 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.

PySide6.QtCore.QProcessEnvironment.isEmpty()#
Return type:

bool

Returns true if this QProcessEnvironment object is empty: that is there are no key=value pairs set.

This method also returns true for objects that were constructed using QProcessEnvironment::InheritFromParent.

PySide6.QtCore.QProcessEnvironment.keys()#
Return type:

list of strings

Returns a list containing all the variable names in this QProcessEnvironment object.

The returned list is empty for objects constructed using QProcessEnvironment::InheritFromParent.

PySide6.QtCore.QProcessEnvironment.__ne__(other)#
Parameters:

otherPySide6.QtCore.QProcessEnvironment

Return type:

bool

Returns true if this and the other QProcessEnvironment objects are different.

See also

operator==()

PySide6.QtCore.QProcessEnvironment.__eq__(other)#
Parameters:

otherPySide6.QtCore.QProcessEnvironment

Return type:

bool

Returns true if this and the other QProcessEnvironment objects are equal.

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.

See also

operator!=() contains()

PySide6.QtCore.QProcessEnvironment.remove(name)#
Parameters:

name – str

Removes the environment variable identified by name from this QProcessEnvironment object. If that variable did not exist before, nothing happens.

PySide6.QtCore.QProcessEnvironment.swap(other)#
Parameters:

otherPySide6.QtCore.QProcessEnvironment

Swaps this process environment instance with other. This function is very fast and never fails.

static PySide6.QtCore.QProcessEnvironment.systemEnvironment()#
Return type:

PySide6.QtCore.QProcessEnvironment

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 like setenv or putenv have been called.

However, note that repeated calls to this function will recreate the QProcessEnvironment object, which is a non-trivial operation.

PySide6.QtCore.QProcessEnvironment.toStringList()#
Return type:

list of strings

Converts this 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.

PySide6.QtCore.QProcessEnvironment.value(name[, defaultValue=""])#
Parameters:
  • name – str

  • defaultValue – str

Return type:

str

Searches this QProcessEnvironment object for a variable identified by name and returns its value. If the variable is not found in this object, then defaultValue is returned instead.