Qt 6.x
The Qt SDK
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
QProcessEnvironment Class Reference

\inmodule QtCore More...

#include <qprocess.h>

+ Collaboration diagram for QProcessEnvironment:

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.
 
QProcessEnvironmentoperator= (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
 

Detailed Description

\inmodule QtCore

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

\reentrant

Since
4.6

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.

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

Definition at line 30 of file qprocess.h.

Member Enumeration Documentation

◆ Initialization

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.

Since
6.3
Enumerator
InheritFromParent 

Definition at line 33 of file qprocess.h.

Constructor & Destructor Documentation

◆ QProcessEnvironment() [1/3]

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.

◆ QProcessEnvironment() [2/3]

QProcessEnvironment::QProcessEnvironment ( 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.

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

See also
inheritsFromParent(), systemEnvironment()
Since
6.3

Definition at line 151 of file qprocess.cpp.

◆ QProcessEnvironment() [3/3]

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::~QProcessEnvironment ( )

Frees the resources associated with this QProcessEnvironment object.

Definition at line 156 of file qprocess.cpp.

Member Function Documentation

◆ clear()

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(), systemEnvironment()

Definition at line 247 of file qprocess.cpp.

References QMap< Key, T >::clear(), QSharedDataPointer< T >::constData(), and QProcessEnvironmentPrivate::vars.

+ Here is the call graph for this function:

◆ contains()

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(), value()

Definition at line 262 of file qprocess.cpp.

References QMap< Key, T >::contains(), QProcessEnvironmentPrivate::prepareName(), and QProcessEnvironmentPrivate::vars.

+ Here is the call graph for this function:

◆ inheritsFromParent()

bool QProcessEnvironment::inheritsFromParent ( ) const

Returns true if this QProcessEnvironment was constructed using {QProcessEnvironment::InheritFromParent}.

Since
6.3
See also
isEmpty()

Definition at line 233 of file qprocess.cpp.

◆ insert() [1/2]

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.

Since
4.8

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

+ Here is the call graph for this function:

◆ insert() [2/2]

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(), value()

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isEmpty()

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(), inheritsFromParent()

Definition at line 220 of file qprocess.cpp.

References QMap< Key, T >::isEmpty(), and QProcessEnvironmentPrivate::vars.

+ Here is the call graph for this function:

◆ keys()

QStringList QProcessEnvironment::keys ( ) const
Since
4.8

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

+ Here is the call graph for this function:

◆ operator!=()

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

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

See also
operator==()

Definition at line 45 of file qprocess.h.

References other().

+ Here is the call graph for this function:

◆ operator=()

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

+ Here is the call graph for this function:

◆ operator==()

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()

Definition at line 203 of file qprocess.cpp.

References other(), and QProcessEnvironmentPrivate::vars.

+ Here is the call graph for this function:

◆ remove()

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(), value()

Definition at line 296 of file qprocess.cpp.

References QSharedDataPointer< T >::constData(), QSharedDataPointer< T >::data(), QMap< Key, T >::remove(), and QProcessEnvironmentPrivate::vars.

+ Here is the call graph for this function:

◆ swap()

void QProcessEnvironment::swap ( QProcessEnvironment other)
inlinenoexcept
Since
5.0

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

Definition at line 42 of file qprocess.h.

References d, and other().

+ Here is the call graph for this function:

◆ systemEnvironment()

QProcessEnvironment QProcessEnvironment::systemEnvironment ( )
static

Definition at line 10 of file qprocess_darwin.mm.

References toLocal8Bit().

Referenced by startProcess().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toStringList()

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(), QProcess::setProcessEnvironment()

Definition at line 336 of file qprocess.cpp.

References QProcessEnvironmentPrivate::toList().

+ Here is the call graph for this function:

◆ value()

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(), remove()

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.

+ Here is the call graph for this function:

Friends And Related Symbol Documentation

◆ QProcessEnvironmentPrivate

friend class QProcessEnvironmentPrivate
friend

Definition at line 67 of file qprocess.h.

◆ QProcessPrivate

friend class QProcessPrivate
friend

Definition at line 66 of file qprocess.h.


The documentation for this class was generated from the following files: