6.0.0-rc4Source

QProcessEnvironment Class

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

Header#include <QProcessEnvironment>
CMaketarget_link_libraries(app PRIVATE Nt::Core)
ModuleNt Core C++ Classes

List of all members, including inherited members

Public Types

Public Functions

QProcessEnvironment()
QProcessEnvironment(Initialization)
voidswap(QProcessEnvironment &other)
boolisEmpty() const
boolinheritsFromParent() const
voidclear()
boolcontains(const QString &name) const
voidinsert(const QString &name, const QString &value)
voidremove(const QString &name)
QStringvalue(const QString &name, const QString &defaultValue = QString()) const
QStringListtoStringList() const
QStringListkeys() const
voidinsert(const QProcessEnvironment &e)

Static Public Members

QProcessEnvironmentsystemEnvironment()

Detailed Description

A process environment is a set of NAME=value pairs. It is a value class: copies are independent. Use it with QProcess::setProcessEnvironment() to control what a child process sees.

QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert("LANG", "C");
env.remove("DISPLAY");
process.setProcessEnvironment(env);

A default-constructed environment is empty; a child started with it has no variables at all. An environment constructed with InheritFromParent is a placeholder that makes the child inherit the parent's environment, which is what a QProcess does until an environment is set. Modifying such a placeholder turns it into an ordinary (initially empty) environment.

See also QProcess.

Differences from Qt

Names and values are stored as QString in a sorted map, so keys() and toStringList() are sorted by name. Names and values are converted to UTF-8 when the child is started. There is no case-insensitive Windows mode.

Member Type Documentation

enum QProcessEnvironment::Initialization

ConstantDescription
QProcessEnvironment::InheritFromParentCreate a placeholder that makes the child process inherit the environment of the parent process.

Member Function Documentation

QProcessEnvironment::QProcessEnvironment()

Constructs an empty environment. A child process started with it has no environment variables.

QProcessEnvironment::QProcessEnvironment(Initialization)

Constructs a placeholder environment that makes the child process inherit the environment of the parent process.

See also inheritsFromParent().

void QProcessEnvironment::clear()

Removes all variables. The environment no longer inherits from the parent.

See also remove() and isEmpty().

bool QProcessEnvironment::contains(const QString &name) const

Returns true if the environment contains a variable called name; otherwise returns false.

See also insert() and value().

bool QProcessEnvironment::inheritsFromParent() const

Returns true if this object is an unmodified placeholder created with InheritFromParent; otherwise returns false.

See also QProcessEnvironment(Initialization).

void QProcessEnvironment::insert(const QString &name, const QString &value)

Inserts the variable name with the value value, replacing an existing variable of that name.

See also remove() and value().

void QProcessEnvironment::insert(const QProcessEnvironment &e)

This is an overloaded function.

Inserts all variables of e into this environment. Variables that exist in both take the value from e. Does nothing if e is an inheriting placeholder.

bool QProcessEnvironment::isEmpty() const

Returns true if this environment has no variables, which includes an inheriting placeholder; otherwise returns false.

See also clear() and inheritsFromParent().

QStringList QProcessEnvironment::keys() const

Returns the names of all variables, sorted.

See also toStringList().

void QProcessEnvironment::remove(const QString &name)

Removes the variable name if it exists.

See also insert() and contains().

void QProcessEnvironment::swap(QProcessEnvironment &other)

Exchanges this environment with other.

[static] QProcessEnvironment QProcessEnvironment::systemEnvironment()

Returns a copy of the environment of the calling process.

See also QProcess::systemEnvironment().

QStringList QProcessEnvironment::toStringList() const

Returns the variables as a list of NAME=value strings, sorted by name.

See also keys().

QString QProcessEnvironment::value(const QString &name, const QString &defaultValue = QString()) const

Returns the value of the variable name, or defaultValue if it does not exist.

See also contains() and insert().