CopperSpice API  1.7.2
QProcessEnvironment Class Reference

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

Public Methods

 QProcessEnvironment ()
 
 QProcessEnvironment (const QProcessEnvironment &other)
 
 ~QProcessEnvironment ()
 
void clear ()
 
bool contains (const QString &name) const
 
void insert (const QProcessEnvironment &e)
 
void insert (const QString &name, const QString &value)
 
bool isEmpty () const
 
QStringList keys () const
 
bool operator!= (const QProcessEnvironment &other) const
 
QProcessEnvironment & operator= (const QProcessEnvironment &other)
 
QProcessEnvironment & operator= (QProcessEnvironment &&other)
 
bool operator== (const QProcessEnvironment &other) const
 
void remove (const QString &name)
 
void swap (QProcessEnvironment &other)
 
QStringList toStringList () const
 
QString value (const QString &name, const QString &defaultValue=QString ()) const
 

Static Public Methods

static QProcessEnvironment systemEnvironment ()
 

Detailed Description

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

The environment of a process 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 is meant to be used along with QProcess, to set the environment for child processes. The class can not be used to change the current process 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 perform a case insensitive comparison.

See also
QProcess, QProcess::systemEnvironment(), QProcess::setProcessEnvironment()

Constructor & Destructor 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.

QProcessEnvironment::QProcessEnvironment ( const QProcessEnvironment &  other)

Creates a QProcessEnvironment object that is a copy of other.

QProcessEnvironment::~QProcessEnvironment ( )

Destroys the resources associated with this QProcessEnvironment object.

Method Documentation

void QProcessEnvironment::clear ( )

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

See also
isEmpty(), systemEnvironment()
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 transformation is applied.

See also
insert(), value()
void QProcessEnvironment::insert ( const QProcessEnvironment &  e)

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

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

See also
contains(), remove(), value()
bool QProcessEnvironment::isEmpty ( ) const

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

See also
clear(), systemEnvironment(), insert()
QStringList QProcessEnvironment::keys ( ) const

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

bool QProcessEnvironment::operator!= ( const QProcessEnvironment &  other) const
inline

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

See also
operator==()
QProcessEnvironment & QProcessEnvironment::operator= ( const QProcessEnvironment &  other)

Copies the contents of the other QProcessEnvironment object into this one.

QProcessEnvironment & QProcessEnvironment::operator= ( QProcessEnvironment &&  other)
inline

Move assigns from other and returns a reference to this object.

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.

See also
operator!=(), contains()
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 transformation is applied.

See also
contains(), insert(), value()
void QProcessEnvironment::swap ( QProcessEnvironment &  other)
inline

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

QProcessEnvironment QProcessEnvironment::systemEnvironment ( )
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 or putenv have been called.

Note that repeated calls to this method 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 method 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.

See also
systemEnvironment(), QProcess::systemEnvironment(), QProcess::environment(), QProcess::setEnvironment()
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.Are

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 transformation is applied.

See also
contains(), insert(), remove()