![]() |
Qt 6.x
The Qt SDK
|
\inmodule QtCore More...
#include <qprocess.h>
Public Types | |
enum | Initialization { InheritFromParent } |
This enum contains a token that is used to disambiguate constructors. More... | |
Public Member Functions | |
QProcessEnvironment () | |
Creates a new QProcessEnvironment object. | |
QProcessEnvironment (Initialization) noexcept | |
Creates an object that when set on QProcess will cause it to be executed with environment variables inherited from its parent process. | |
QProcessEnvironment (const QProcessEnvironment &other) | |
Creates a QProcessEnvironment object that is a copy of other. | |
~QProcessEnvironment () | |
Frees the resources associated with this QProcessEnvironment object. | |
QProcessEnvironment & | operator= (const QProcessEnvironment &other) |
Copies the contents of the other QProcessEnvironment object into this one. | |
void | swap (QProcessEnvironment &other) noexcept |
bool | operator== (const QProcessEnvironment &other) const |
Returns true if this and the other QProcessEnvironment objects are equal. | |
bool | operator!= (const QProcessEnvironment &other) const |
Returns true if this and the other QProcessEnvironment objects are different. | |
bool | isEmpty () const |
Returns true if this QProcessEnvironment object is empty: that is there are no key=value pairs set. | |
bool | inheritsFromParent () const |
Returns true if this QProcessEnvironment was constructed using {QProcessEnvironment::InheritFromParent}. | |
void | clear () |
Removes all key=value pairs from this QProcessEnvironment object, making it empty. | |
bool | contains (const QString &name) const |
Returns true if the environment variable of name name is found in this QProcessEnvironment object. | |
void | insert (const QString &name, const QString &value) |
Inserts the environment variable of name name and contents value into this QProcessEnvironment object. | |
void | remove (const QString &name) |
Removes the environment variable identified by name from this QProcessEnvironment object. | |
QString | value (const QString &name, const QString &defaultValue=QString()) const |
Searches this QProcessEnvironment object for a variable identified by name and returns its value. | |
QStringList | toStringList () const |
Converts this QProcessEnvironment object into a list of strings, one for each environment variable that is set. | |
QStringList | keys () const |
void | insert (const QProcessEnvironment &e) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
Static Public Member Functions | |
static QProcessEnvironment | systemEnvironment () |
Friends | |
class | QProcessPrivate |
class | QProcessEnvironmentPrivate |
\inmodule QtCore
The QProcessEnvironment class holds the environment variables that can be passed to a program.
\reentrant
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.
Definition at line 30 of file qprocess.h.
This enum contains a token that is used to disambiguate constructors.
\value InheritFromParent A QProcessEnvironment will be created that, when set on a QProcess, causes it to inherit variables from its parent.
Enumerator | |
---|---|
InheritFromParent |
Definition at line 33 of file qprocess.h.
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).
Definition at line 131 of file qprocess.cpp.
|
noexcept |
Creates an object that when set on QProcess will cause it to be executed with environment variables inherited from its parent process.
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).
Definition at line 151 of file qprocess.cpp.
QProcessEnvironment::QProcessEnvironment | ( | const QProcessEnvironment & | other | ) |
Creates a QProcessEnvironment object that is a copy of other.
Definition at line 163 of file qprocess.cpp.
QProcessEnvironment::~QProcessEnvironment | ( | ) |
Frees the resources associated with this QProcessEnvironment object.
Definition at line 156 of file qprocess.cpp.
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.
Definition at line 247 of file qprocess.cpp.
References QMap< Key, T >::clear(), QSharedDataPointer< T >::constData(), and QProcessEnvironmentPrivate::vars.
bool QProcessEnvironment::contains | ( | const QString & | name | ) | const |
Returns true
if the environment variable of name name is found in this QProcessEnvironment object.
Definition at line 262 of file qprocess.cpp.
References QMap< Key, T >::contains(), QProcessEnvironmentPrivate::prepareName(), and QProcessEnvironmentPrivate::vars.
bool QProcessEnvironment::inheritsFromParent | ( | ) | const |
Returns true
if this QProcessEnvironment was constructed using {QProcessEnvironment::InheritFromParent}.
Definition at line 233 of file qprocess.cpp.
void QProcessEnvironment::insert | ( | const QProcessEnvironment & | e | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Inserts the contents of e in this QProcessEnvironment object. Variables in this object that also exist in e will be overwritten.
Definition at line 366 of file qprocess.cpp.
References e, and QProcessEnvironmentPrivate::insert().
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.
Definition at line 281 of file qprocess.cpp.
References QSharedDataPointer< T >::detach(), QMap< Key, T >::insert(), QProcessEnvironmentPrivate::prepareName(), QProcessEnvironmentPrivate::prepareValue(), and QProcessEnvironmentPrivate::vars.
Referenced by QProcessEnvironmentPrivate::fromList(), and startProcess().
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}.
Definition at line 220 of file qprocess.cpp.
References QMap< Key, T >::isEmpty(), and QProcessEnvironmentPrivate::vars.
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}.
Definition at line 352 of file qprocess.cpp.
References QProcessEnvironmentPrivate::keys().
|
inline |
Returns true
if this and the other QProcessEnvironment objects are different.
Definition at line 45 of file qprocess.h.
References other().
QProcessEnvironment & QProcessEnvironment::operator= | ( | const QProcessEnvironment & | other | ) |
Copies the contents of the other QProcessEnvironment object into this one.
Definition at line 172 of file qprocess.cpp.
References other().
bool QProcessEnvironment::operator== | ( | const QProcessEnvironment & | other | ) | const |
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.
Definition at line 203 of file qprocess.cpp.
References other(), and QProcessEnvironmentPrivate::vars.
Removes the environment variable identified by name from this QProcessEnvironment object.
If that variable did not exist before, nothing happens.
Definition at line 296 of file qprocess.cpp.
References QSharedDataPointer< T >::constData(), QSharedDataPointer< T >::data(), QMap< Key, T >::remove(), and QProcessEnvironmentPrivate::vars.
|
inlinenoexcept |
Swaps this process environment instance with other. This function is very fast and never fails.
Definition at line 42 of file qprocess.h.
|
static |
Definition at line 10 of file qprocess_darwin.mm.
References toLocal8Bit().
Referenced by startProcess().
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.
Definition at line 336 of file qprocess.cpp.
References QProcessEnvironmentPrivate::toList().
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.
Definition at line 311 of file qprocess.cpp.
References QMap< Key, T >::constEnd(), QMap< Key, T >::constFind(), it, QProcessEnvironmentPrivate::prepareName(), QProcessEnvironmentPrivate::valueToString(), and QProcessEnvironmentPrivate::vars.
|
friend |
Definition at line 67 of file qprocess.h.
|
friend |
Definition at line 66 of file qprocess.h.