Hatagashira
Hatagashira

Reputation: 149

default file locations per platform?

I'm making a (qt) cross platform application that stores both cache and settings files. After a lot of searching, i still haven't found how and where to store them. Please note that i want to use QT's stuff only where i would otherwise reinvent the wheel or save insane amounts of time; i want absolute control over the behavior of the application and qt is rather random or inefficient at times.

For linux, the default would be /etc//, but there's no write access there and my app writes changes to it's config file. for cache, that would be /var//, but by default there is no write access either. the settings and cache should preferably be user independent as it's server software.

I have thought of several solutions, but they don't seem very elegant:

any ideas? what's best practice? where does this stuff go on windows and mac?

Some clarification: It's a server application that is supposed to run independently of a single user, so it's not desired to store anything at all in /home. It's also not using any gui features of QT, the server is going to be managed by either settings files or a separate GUI that communicates with the server over IP.

Upvotes: 2

Views: 1199

Answers (4)

Al2O3
Al2O3

Reputation: 3213

Why not store it in the same folder with the executable file:

QString fileName;

fileName = qApp->applicationDirPath();

fileName += "...what you want...";

QFile* file = new QFile(fileName);

Upvotes: 0

Liang Qi
Liang Qi

Reputation: 141

I don't think there is a ready Qt class to do it which following the same behaviour like each platform does.

But I think you could try to unify it for your own app on different platforms, for example, in $HOME/.yourapp directory or sth like it. For this way, QDesktopServices::storageLocation() could help you a bit.

http://doc.qt.digia.com/4.7/qdesktopservices.html#storageLocation

Hope it helps.

Upvotes: 0

Frank Osterfeld
Frank Osterfeld

Reputation: 25165

User applications don't store user-writable data such as configuration files or caches in /etc or /var, they usually use and should use $HOME/.appname, or, nowadays often used, $HOME/.config/appname (config) and $HOME/.local/ (for data). Qt should do a good job here for the config data if you use QSettings and set the Application name etc. /etc is for daemons, system configuration and the like, not for user applications. There might be readonly default configuration in /usr/share etc., but that's never writable by users. Sharing user-writable data will also give you a lot of syncing/locking headaches when multiple users on the system run the application simultaneously.

On Windows on OS X, user-writable configuration/data also goes to folders in the user directory, that'd be $HOME/Library/Application\ Support on Mac, and the registry plus C:\users\$Username\Application Data on Windows (the exact path depends on the Windows version. The environment variable %APPDATA% points to the location)).

To deviate from those standards, for a user/UI application (opposed to a system-wide daemon/service, where using /etc, /var is common practice) you should have very strong reasons, as they'll contradict what's expected on the systems, especially on Linux and also OS X. E.g., you'd need an installer on OS X, which is highly uncommon for user applications there. Users and especially Admins will hate you.

Upvotes: 0

UmNyobe
UmNyobe

Reputation: 22910

If you really want to use these folders your application should be executed partially or completely with root privileges.

Another thing you can do is:

  • setup a work directory myDir for your application, and everything is stored inside this work directory (the same way qtcreator does if you want an example).
  • Save your directory in a non-user specific location. I think /opt is a good candidate.
  • In myDir the required privilege to access\modify\execute files you want are set up for the users group.
  • myDir itself requires root to delete, but not the files inside.
  • Make the settings for your Qt application kinda self contained using QSettings

Without an installer you will be the installer: moving around executing scripts and commands, and eventually writing an installation document (we are doing this in our startup now and it is just painful, we are in the process of changing to full installer mode)

Note : Not an expert, but using two types of machines as servers seems like you guys are really looking for trouble. Or your app is targeting servers of all types maybe?

Upvotes: 2

Related Questions