PDA

View Full Version : Save log file to "all user\application data\"



stella1016
4th July 2011, 12:56
My application has some configuration file and log file to store.

Q1:
In winxp, i want to save them to "C:/Documents and Settings/All Users/Application data/". I have no idea how to get this location using qt.

Q2:
And in win7, the file structure is different. I am not sure whether the directory should be "C:/Program data".

Q3:
I don't think there is any log data can be written to global location in Linux. Right?

Any one can help?

squidge
4th July 2011, 13:44
Check the Microsoft requirements on MSDN. Eg for Windows 7:

"All application data that must be shared among users on the computer should be stored within ProgramData. All application data exclusive to a specific user and not to be shared with other users of the computer must be stored in Users\<username>\AppData."

As for where the directories are, check out QDesktopServices::storageLocation

kunashir
4th July 2011, 14:16
I used in my project It is:


QDir::homePath()

In Win XP it is C:/Documents and Settings/%USERNAME%/
In win 7 C:/Users/<username>/

stella1016
4th July 2011, 16:01
Check the Microsoft requirements on MSDN. Eg for Windows 7:

"All application data that must be shared among users on the computer should be stored within ProgramData. All application data exclusive to a specific user and not to be shared with other users of the computer must be stored in Users\<username>\AppData."

As for where the directories are, check out QDesktopServices::storageLocation

Thanks.

But QDesktopServices::storageLocation doesn't support "all users\appdata", but only for current user.

For example:
ini_path = QDesktopServices::storageLocation(QDesktopServices ::DataLocation);
gives "<username>\local settings\AppData".

PS:
ini_path = getenv("ProgramData"); // "<username>\AppData".
ini_path = getenv("ALLUSERSPROFILE"); // "all users\".

But I need exactly "all users\appdata".

Added after 1 2 minutes:

I found the solution:


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

:cool: