QProcessEnvironment Class | Qt Core (original) (raw)
The QProcessEnvironment class holds the environment variables that can be passed to a program. More...
This class is equality-comparable.
Member Function Documentation
QProcessEnvironment::QProcessEnvironment()
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).
[noexcept, 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.
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).
This function was introduced in Qt 6.3.
See also inheritsFromParent() and systemEnvironment().
QProcessEnvironment::QProcessEnvironment(const QProcessEnvironment &other)
Creates a QProcessEnvironment object that is a copy of other.
[noexcept]
QProcessEnvironment::~QProcessEnvironment()
Frees the resources associated with this QProcessEnvironment object.
void 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.
See also isEmpty() and systemEnvironment().
bool QProcessEnvironment::contains(const QString &name) const
Returns true
if the environment variable of name name is found in this QProcessEnvironment object.
See also insert() and value().
[since 6.3]
bool QProcessEnvironment::inheritsFromParent() const
Returns true
if this QProcessEnvironment was constructed using QProcessEnvironment::InheritFromParent
.
This function was introduced in Qt 6.3.
See also isEmpty().
void QProcessEnvironment::insert(const QString &name, const QString &value)
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.
See also contains(), remove(), and value().
void QProcessEnvironment::insert(const QProcessEnvironment &e)
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.
bool QProcessEnvironment::isEmpty() const
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
.
See also clear(), systemEnvironment(), insert(), and inheritsFromParent().
QStringList QProcessEnvironment::keys() const
Returns a list containing all the variable names in this QProcessEnvironment object.
The returned list is empty for objects constructed using QProcessEnvironment::InheritFromParent
.
void QProcessEnvironment::remove(const QString &name)
Removes the environment variable identified by name from this QProcessEnvironment object. If that variable did not exist before, nothing happens.
See also contains(), insert(), and value().
[noexcept]
void QProcessEnvironment::swap(QProcessEnvironment &other)
Swaps this process environment instance with other. This operation is very fast and never fails.
[static]
QProcessEnvironment QProcessEnvironment::systemEnvironment()
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.
See also QProcess::systemEnvironment().
QStringList QProcessEnvironment::toStringList() const
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.
See also systemEnvironment(), QProcess::systemEnvironment(), and QProcess::setProcessEnvironment().
QString QProcessEnvironment::value(const QString &name, const QString &defaultValue = QString()) const
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.
See also contains(), insert(), and remove().
QProcessEnvironment &QProcessEnvironment::operator=(const QProcessEnvironment &other)
Copies the contents of the other QProcessEnvironment object into this one.