I need to get the path to the temporary directory. Is there any difference between the following methods (except for the first one is available in Qt 4)? Which one is better to use?
QDir::tempPath()
QStandardPaths::writableLocation(QStandardPaths::TempLocation)
TL;DR: Prefer QStandardPaths::writableLocation
.
There is no difference on Unix, OS X and Windows. There, they are guaranteed to always return the same thing. To wit - in qstandardpaths_win.cpp
, qstandardpaths_unix.cpp
, qstandardpaths_mac.mm
, and qstandardpaths_winrt.cpp
:
QString QStandardPaths::writableLocation(StandardLocation type) {
switch (type) {
//[...]
case TempLocation:
return QDir::tempPath();
On Android and Haiku, the value returned by QStandardPaths::writableLocation
uses a proper system-specific approach, while the value returned by tempPath
uses the legacy environment-variable based approach that should be considered deprecated on those systems.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With