Qt 4.8
|
The QProcessEnvironment class holds the environment variables that can be passed to a program. More...
#include <qprocess.h>
Public Functions | |
void | clear () |
Removes all key=value pairs from this QProcessEnvironment object, making it empty. More... | |
bool | contains (const QString &name) const |
Returns true if the environment variable of name name is found in this QProcessEnvironment object. More... | |
void | insert (const QString &name, const QString &value) |
Inserts the environment variable of name name and contents value into this QProcessEnvironment object. More... | |
void | insert (const QProcessEnvironment &e) |
Inserts the contents of e in this QProcessEnvironment object. More... | |
bool | isEmpty () const |
Returns true if this QProcessEnvironment object is empty: that is there are no key=value pairs set. More... | |
QStringList | keys () const |
Returns a list containing all the variable names in this QProcessEnvironment object. More... | |
bool | operator!= (const QProcessEnvironment &other) const |
Returns true if this and the other QProcessEnvironment objects are different. More... | |
QProcessEnvironment & | operator= (const QProcessEnvironment &other) |
Copies the contents of the other QProcessEnvironment object into this one. More... | |
bool | operator== (const QProcessEnvironment &other) const |
Returns true if this and the other QProcessEnvironment objects are equal. More... | |
QProcessEnvironment () | |
Creates a new QProcessEnvironment object. More... | |
QProcessEnvironment (const QProcessEnvironment &other) | |
Creates a QProcessEnvironment object that is a copy of other. More... | |
void | remove (const QString &name) |
Removes the environment variable identified by name from this QProcessEnvironment object. More... | |
QStringList | toStringList () const |
Converts this QProcessEnvironment object into a list of strings, one for each environment variable that is set. More... | |
QString | value (const QString &name, const QString &defaultValue=QString()) const |
Searches this QProcessEnvironment object for a variable identified by name and returns its value. More... | |
~QProcessEnvironment () | |
Frees the resources associated with this QProcessEnvironment object. More... | |
Static Public Functions | |
static QProcessEnvironment | systemEnvironment () |
The systemEnvironment function returns the environment of the calling process. More... | |
Properties | |
QSharedDataPointer< QProcessEnvironmentPrivate > | d |
Friends | |
class | QProcessEnvironmentPrivate |
class | QProcessPrivate |
The QProcessEnvironment class holds the environment variables that can be passed to a program.
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. For that reason, this class will not touch the names of the variables. Note as well that Unix environment allows both variable names and contents to contain arbitrary binary data (except for the NUL character), but this is not supported by QProcessEnvironment. This class only supports names and values that are encodable by the current locale settings (see QTextCodec::codecForLocale).
On Windows, the variable names are case-insensitive. Therefore, QProcessEnvironment will always uppercase the names and do case-insensitive comparisons.
On Windows CE, the concept of environment does not exist. This class will keep the values set for compatibility with other platforms, but the values set will have no effect on the processes being created.
Definition at line 68 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.
Definition at line 216 of file qprocess.cpp.
QProcessEnvironment::QProcessEnvironment | ( | const QProcessEnvironment & | other | ) |
Creates a QProcessEnvironment object that is a copy of other.
Definition at line 231 of file qprocess.cpp.
QProcessEnvironment::~QProcessEnvironment | ( | ) |
Frees the resources associated with this QProcessEnvironment object.
Definition at line 224 of file qprocess.cpp.
void QProcessEnvironment::clear | ( | ) |
Removes all key=value pairs from this QProcessEnvironment object, making it empty.
Definition at line 295 of file qprocess.cpp.
bool QProcessEnvironment::contains | ( | const QString & | name | ) | const |
Returns true if the environment variable of name name is found in this QProcessEnvironment object.
On Windows, variable names are case-insensitive, so the key is converted to uppercase before searching. On other systems, names are case-sensitive so no trasformation is applied.
Definition at line 313 of file qprocess.cpp.
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 Windows, variable names are case-insensitive, so this function always uppercases the variable name before inserting. On other systems, names are case-sensitive, so no transformation is applied.
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 337 of file qprocess.cpp.
Referenced by QProcessEnvironmentPrivate::fromList().
void QProcessEnvironment::insert | ( | const QProcessEnvironment & | e | ) |
Inserts the contents of e in this QProcessEnvironment object.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Variables in this object that also exist in e will be overwritten.
Definition at line 435 of file qprocess.cpp.
bool QProcessEnvironment::isEmpty | ( | ) | const |
Returns true if this QProcessEnvironment object is empty: that is there are no key=value pairs set.
Definition at line 283 of file qprocess.cpp.
QStringList QProcessEnvironment::keys | ( | ) | const |
Returns a list containing all the variable names in this QProcessEnvironment object.
Definition at line 417 of file qprocess.cpp.
|
inline |
Returns true if this and the other QProcessEnvironment objects are different.
Definition at line 77 of file qprocess.h.
QProcessEnvironment & QProcessEnvironment::operator= | ( | const QProcessEnvironment & | other | ) |
Copies the contents of the other QProcessEnvironment object into this one.
Definition at line 240 of file qprocess.cpp.
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 266 of file qprocess.cpp.
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.
On Windows, variable names are case-insensitive, so the key is converted to uppercase before searching. On other systems, names are case-sensitive so no trasformation is applied.
Definition at line 355 of file qprocess.cpp.
|
static |
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
ot putenv
have been called.
However, note that repeated calls to this function will recreate the QProcessEnvironment object, which is a non-trivial operation.
Definition at line 499 of file qprocess_unix.cpp.
Referenced by qt_create_commandline().
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 use with the QProcess::setEnvironment function. However, it is recommended to use QProcess::setProcessEnvironment instead since that will avoid unnecessary copying of the data.
Definition at line 400 of file qprocess.cpp.
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.
On Windows, variable names are case-insensitive, so the key is converted to uppercase before searching. On other systems, names are case-sensitive so no trasformation is applied.
Definition at line 374 of file qprocess.cpp.
|
friend |
Definition at line 98 of file qprocess.h.
|
friend |
Definition at line 97 of file qprocess.h.
|
private |
Definition at line 99 of file qprocess.h.
Referenced by clear(), contains(), insert(), isEmpty(), keys(), operator=(), operator==(), qt_create_commandline(), remove(), systemEnvironment(), toStringList(), and value().