Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
Helper functions for working with environment variables.
Returns the numerical value of the environment variable varName. If ok is not null, sets *ok to true or false depending on the success of the conversion.
Equivalent to
qgetenv(varName).toInt(ok, 0)
except that it’s much faster, and can’t throw exceptions.
See also
qgetenv()qEnvironmentVariable()qEnvironmentVariableIsSet()
Returns the numerical value of the environment variable varName. If the variable is not set or could not be parsed as an integer, it returns std::nullopt.
Similar to
qgetenv(varName).toInt(ok, 0)
except that it’s much faster, and can’t throw exceptions.
If a value of zero is semantically the same as an empty or unset variable, applications can use
qEnvironmentVariableIntegerValue(varName).value_or(0)
Do note in this case that failures to parse a value will also produce a zero.
But if a value of zero can be used to disable some functionality, applications can compare the returned std::optional to zero, which will only be true if the variable was set and contained a number that parsed as zero, as in:
qEnvironmentVariableIntegerValue(varName) == 0See also
qgetenv()qEnvironmentVariable()qEnvironmentVariableIsSet()
Returns whether the environment variable varName is empty.
Equivalent to
qgetenv(varName).isEmpty()
except that it’s potentially much faster, and can’t throw exceptions.
See also
qgetenv()qEnvironmentVariable()qEnvironmentVariableIsSet()
Returns whether the environment variable varName is set.
Equivalent to
def qgetenv(varName).isNull():
except that it’s potentially much faster, and can’t throw exceptions.
See also
qgetenv()qEnvironmentVariable()qEnvironmentVariableIsEmpty()qEnvironmentVariableIntegerValue()
Returns the value of the environment variable with name varName as a QByteArray . If no variable by that name is found in the environment, this function returns a default-constructed QByteArray .
The Qt environment manipulation functions are thread-safe, but this requires that the C library equivalent functions like getenv and putenv are not directly called.
To convert the data to a QString use fromLocal8Bit() .
Note
on desktop Windows, qgetenv() may produce data loss if the original string contains Unicode characters not representable in the ANSI encoding. Use qEnvironmentVariable() instead. On Unix systems, this function is lossless.
See also
qputenv() qEnvironmentVariable() qEnvironmentVariableIsSet() qEnvironmentVariableIsEmpty() qEnvironmentVariableIntegerValue()
This function sets the value of the environment variable named varName. It will create the variable if it does not exist. It returns 0 if the variable could not be set.
Calling qputenv with an empty value removes the environment variable on Windows, and makes it set (but empty) on Unix. Prefer using qunsetenv() for fully portable behavior.
Note
qputenv() was introduced because putenv() from the standard C library was deprecated in VC2005 (and later versions). qputenv() uses the replacement function in VC, and calls the standard C library’s implementation on all other platforms.
Note
In Qt versions prior to 6.5, the value argument was QByteArray , not QByteArrayView .
See also
qgetenv() qEnvironmentVariable()
This function deletes the variable varName from the environment.
Returns true on success.
See also
qputenv()qgetenv()qEnvironmentVariable()