I'm looking for an equivalent of the getenv function.
相关问题
- Sorting 3 numbers without branching [closed]
- QML: Cannot read property 'xxx' of undefin
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
相关文章
- ubuntu20.4中c#通过c++库调用python脚本
- Qt槽函数自动执行多遍
- How should I configure log4net to write to %LOCALA
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
Qt has a wrapper around
getenv()
, calledqgetenv()
.getenv()
is a standard function, but Visual Studio has deprecated it which is why Qt provides theqgetenv()
wrapper.Note that if you're interested in getting standard filesystem locations (like the home directory, application data directory, etc.) you should instead use
QDesktopServices::storageLocation()
(Qt 4) orQStandardPaths::writableLocation()
(Qt 5).For Qt, there is also a "high-level" approach when accessing environment variables. This only works, if your Qt application runs within a QCoreApplication, which should be the case for most Qt applications.
In that case, you can use QProcessEnvironment, for Qt versions of at least 4.6. You can access the current process environment by using
and you can query any variable via
This should be more convenient that using the getenv/qgetenv approach in most cases as this shadows the operating-system implementation in a more generic way and IMHO it is also a more "Qt-alike" approach.