QProcessEnvironment 類

The QProcessEnvironment 類保持可以被傳遞給程序的環境變量。 更多...

頭: #include <QProcessEnvironment>
Since: Qt 4.6

注意: 此類的所有函數 可重入 .

公共函數

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

靜態公共成員

QProcessEnvironment systemEnvironment ()

詳細描述

The QProcessEnvironment 類保持可以被傳遞給程序的環境變量。

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.

另請參閱 QProcess , QProcess::systemEnvironment (),和 QProcess::setProcessEnvironment ().

成員函數文檔編製

QProcessEnvironment:: QProcessEnvironment ()

創建新的 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 )

創建 QProcessEnvironment object that is a copy of other .

QProcessEnvironment:: ~QProcessEnvironment ()

Frees the resources associated with this QProcessEnvironment 對象。

void QProcessEnvironment:: clear ()

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

另請參閱 isEmpty () 和 systemEnvironment ().

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

Returns true if the environment variable of name name 被找到在此 QProcessEnvironment 對象。

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.

另請參閱 insert () 和 value ().

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

插入環境變量按名稱 name 和內容 value 到此 QProcessEnvironment 對象。若變量已經存在,以新值替換它。

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.

在大多數係統,插入沒有內容的變量對應用程序與根本沒有設置變量的效果相同。不管怎樣,為保證不存在不兼容,要移除變量請使用 remove () 函數。

另請參閱 contains (), remove (),和 value ().

void QProcessEnvironment:: insert (const QProcessEnvironment & e )

這是重載函數。

插入內容為 e 在此 QProcessEnvironment 對象。在此對象中的變量還存在於 e 會被覆寫。

該函數在 Qt 4.8 引入。

bool QProcessEnvironment:: isEmpty () const

返迴 true,若此 QProcessEnvironment 對象為空:沒有設置 "鍵=值" 對。

另請參閱 clear (), systemEnvironment (),和 insert ().

QStringList QProcessEnvironment:: keys () const

返迴包含所有變量名稱的列錶在此 QProcessEnvironment 對象。

該函數在 Qt 4.8 引入。

void QProcessEnvironment:: remove (const QString & name )

移除環境變量標識通過 name 從此 QProcessEnvironment 對象。若變量之前不存在,什麼都不發生。

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.

另請參閱 contains (), insert (),和 value ().

[static] QProcessEnvironment QProcessEnvironment:: systemEnvironment ()

The systemEnvironment function returns the environment of the calling process.

它被返迴作為 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 有被調用。

However, note that repeated calls to this function will recreate the QProcessEnvironment object, which is a non-trivial operation.

該函數在 Qt 4.6 引入。

另請參閱 QProcess::systemEnvironment ().

QStringList QProcessEnvironment:: toStringList () const

轉換此 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.

另請參閱 systemEnvironment (), QProcess::systemEnvironment (), QProcess::environment (),和 QProcess::setEnvironment ().

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

搜索此 QProcessEnvironment object for a variable identified by name and returns its value. If the variable is not found in this object, then defaultValue 被返迴取而代之。

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.

另請參閱 contains (), insert (),和 remove ().

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

Returns true if this and the other QProcessEnvironment 對象不同。

另請參閱 operator== ().

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

拷貝內容從 other QProcessEnvironment 對象到此對象。

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

Returns true if this and the other QProcessEnvironment 對象相等。

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.

另請參閱 operator!= () 和 contains ().