PDA

View Full Version : Qt4: How to get the Common Application Data folder path?



Ankitha Varsha
20th October 2008, 07:34
Hi,

I am porting MFC code to Qt4.

There is a method in MFC namely SHGetFolderPath which gives the path of the folder given the CSIDL value.

For the current code I am porting, the CSDIL value is "CSIDL_COMMON_APPDATA" Which yeilds a typical path "C:\Documents and Settings\All Users\Application Data".

In Qt, the nearest thing I know is QDesktopServices::StandardLocation. But for the location/path that CSIDL_COMMON_APPDATA returns in MFC, I am not sure how to get the same location in Qt.

Please help.

/Ankitha.

aamer4yu
20th October 2008, 08:10
You can use the MFC code in Qt too , cant you :)

Ankitha Varsha
20th October 2008, 08:23
Oh no.
The project is multiplatform
And the purpose it is to port all the MFC to code to Qt.

kernel_panic
20th October 2008, 09:25
i think you have to do use QDir::homePath() or QDir::rootPath().
Eg:
QString appDir = QDir::homePath() + "/Application Data/";
QString appDir = QDir::rootPath() + /"Documents and Settings/All Users/Application Data/";

Ankitha Varsha
20th October 2008, 09:31
QString appDir = QDir::homePath() + "/Application Data/";
QString appDir = QDir::rootPath() + /"Documents and Settings/All Users/Application Data/";

In the above code, if the platforms are different, is it possible that the common Application Data path might differ? I mean to ask, will there be "Documents and Settings/All Users/Application Data/" under root path for that platform , be it windows, Unix or Mac? I am sorry if the question is silly, I have been working on only windows since very long time.

/Ankitha

kernel_panic
20th October 2008, 09:54
use Q_WS_WIN Q_WS_X11 and Q_WS_MAC for getting the current path:
#ifdef Q_WS_WIN
QString appDir = QDir::homePath() + "/Application Data/";
#elif defined(Q_WS_X11)
QString appDir = QDir::homePath() + "/.config/yourapp/";
#endif

aamer4yu
20th October 2008, 11:10
I mean to ask, will there be "Documents and Settings/All Users/Application Data/" under root path for that platform , be it windows, Unix or Mac?
NO.

Go as kenel_panic has suggested.

Ankitha Varsha
20th October 2008, 11:37
Neat :)
Thanks a lot :)

elcuco
20th October 2008, 22:54
be warned that those directories might have different names, depending on the windows locale.

Check MSDN for the correct function to use. On linux, just put stuff on the user's home directory, no real standard here.

Lesiok
21st October 2008, 07:25
On Windows all this information You can read from system register from key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Curr entVersion\Explorer\Shell Folders. In example to read location of All User Desktop :

QSettings register("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\ CurrentVersion\\Explorer\\Shell Folders", QSettings::NativeFormat);
QString allUserDesktop( register.value("Common Desktop").toString());

Ankitha Varsha
21st October 2008, 12:14
This was very useful.
Thank you so much.