views:

63

answers:

3

On Windows, there is a standard location for application data that is shared in common with all users on the machine (i.e. in Vista/7, (root):\ProgramData). I'm looking for a way to get such a folder on other platforms using Qt.

  • Does Qt provide a built-in method for doing this? (QDesktopServices looked promising, but does not seem to provide this option.)
  • If not, what are the standard locations on Linux and Mac OS X systems for shared application data? Is /usr/share the correct place? Is there a standard at all?

[CLARIFICATION] This is for mutable data.

+2  A: 

The File System Hierarchy Standard suggest that /usr/share should be used for read-only architecture independent data files, and /var/lib should be used for state information pertaining to an application or the system.

You didn't specify whether you're referring to read-only or mutable state, but the wording of your question (specifically the comparison to %COMMONAPPDATA%) suggests mutable state, in which case /var/lib would be appropiate. Don't forget to have a user group with write rights to your subdirectory there available (or created by the package installation script) and have the sysadmin add the appropiate users to that group.

Mihai Limbășan
Various directories under /var may be what you are looking for. The output of <code>man hier</code> describes the file hierarchy in some detail.
BillThor
+4  A: 

I don't know if Qt provides an API for that. Here's the OS X specific information.

On OS X, it depends whether it's a GUI app or unix level support libraries. For a GUI app, it's the standard practice to have all the read-only data shared by all users inside the app bundle itself. Typically you have

  YourApp.app/
  YourApp.app/Contents
  YourApp.app/Contents/MacOS
  YourApp.app/Contents/MacOS/YouApp      .... this is the binary
  YourApp.app/Contents/Resources/        .... here are all the shared data

The GUI presents the directory YourApp.app as the application itself, so that you can copy/move it around without any problem. If that's not possible, it's recommended to use the subdirectory of

/Library/Application Support/name_of_your_app/

for data shared among users.

It's a bad idea to have a mutable, shared data among users on a machine; in general it's impossible due to the access restrictions. Note that a standard user might not have, and in fact usually does not have an administrative right to write into a shared location.

For mutable data specific to a user, use

~/Library/Application Support/name_of_your_app/

See this Apple guideline for more info.

Yuji
A: 

On Mac OS, one solution is to use the /Users/Shared directory, since it is read/write for all users, and is therefore mutable for everyone. Have to make sure any files you create in there are read/write for everyone too.

Or you can use app support as suggested by others, and making any files you need to be mutable read/write for everyone, but that means an admin needs to create them first, either through an installer or first run, which is a little ugly.

My company is using Users/Shared for exactly this purpose, but I don't know how "neat" it is considered.

Finn