Several variants:
Qt already has paths to many of these (cross-platform) in QDesktopServices . QDesktopServices::storageLocation(StandardLocation) method.
For some, you can use qgetenv (as mentioned above).
If all else fails, you can directly call the SHGetSpecialFolderPath method in the Shell32 library. A list of options is available on the Microsoft website .
Here is an example of the latter:
static QString getWindowsPath(int path_to_get) { typedef BOOL (WINAPI*GetSpecialFolderPath)(HWND, LPWSTR, int, BOOL); QLibrary shell32_lib(QLatin1String("shell32")); GetSpecialFolderPath SHGetSpecialFolderPath = (GetSpecialFolderPath)shell32_lib.resolve("SHGetSpecialFolderPathW"); QScopedPointer<wchar_t> w_path(new wchar_t[MAX_PATH]); SHGetSpecialFolderPath(0, w_path.data(), path_to_get, FALSE); return QString::fromWCharArray(w_path.data()); }
(Actually, SHGetSpecialFolderPath been replaced with SHGetKnownFolderPath since Vista, so if you know that you are targeting only Windows 7, you should use this instead. It uses the value KNOWNFOLDERID .)
Dave mateer
source share