tags:

views:

1609

answers:

7
  • linux: $HOME/.config
  • windows: %APPDATA%
  • mac os: $HOME/.config

It can be set using http://doc.trolltech.com/4.4/qsettings.html#setPath, but it seems as I am not able to retrieve it.

http://doc.trolltech.com/4.4/qlibraryinfo.html#location QLibraryInfo::LibrariesPath returns the system wide settings dir, which is not what I want.

Any ideas, or do I have to code it separately for each platform?

€: I want to create a sub directory, and store files into it. (You may punish me if this is a bad idea)

A: 

What platform are you at?
Might be related or not but in windows, the default is to write QSettings to the registry.

shoosh
i want to store files in this directory. and i already know where they are on each platform, but is there a qt-way to get this info?
Ronny
A: 

Use the class QDir's method currentPath Qt reference

lkristjansen
+1  A: 

As far as I can tell, you can't retrieve the path. In the Qt source, src/corelib/io/qsettings.cpp, there is a function to get the path:

static QString getPath(QSettings::Format format, QSettings::Scope scope)
{
    ...

but it's not accessible from code using Qt. You can't copy it and use it either, because it uses internal Qt globals to store the path...

EDIT: A solution was posted, using QDesktopServices.storageLocation(QDesktopServices.DataLocation) but it doesn't do exactly what the question was asking for, i.e. if I set a custom path using QSettings.setPath() it doesn't reflect the change.

dF
A: 

I read more into the question than there was as it was originally posted. It is clearer after the edits. Ok, so can't you use..

QString QSettings::fileName () const

Returns the path where settings written using this QSettings object are stored.

On Windows, if the format is QSettings::NativeFormat, the return value is a system registry path, not a file path.

Arnold Spence
I don't want the home directory but the settings directory. examples given in the question.
Ronny
The answer has been edited following clarification edits to the question.
Arnold Spence
+1  A: 

Why do you need to know the settings path? If you are going to put settings in it, you could use QSettings. I could see making a subdirectory to hold various settings, but it seems like the easiest way would be to use QSettings directly.

Caleb Huitt - cjhuitt
edited the reason into it. thanks for your help
Ronny
It's potentially megabytes of data - this might slow down the whole settings thing.
Ronny
+3  A: 

This might not answer your question directly: if you want to store per-user persistent data, shouldn't you use QDesktopServices::storageLocation(QDesktopServices::DataLocation) instead?

Ariya Hidayat
/home/user/.local/share/data// is looking good, although it seems not to be QT-specific.Can anyone of you folks try this out on windoze and paste the result in here? That'd be great. thanks
Ronny
On Windows XP, it should be something like "C:\Document and Settings\user\Local Settings\Application Data"
Ariya Hidayat
that's what I wanted. Big thanks.
Ronny
+2  A: 

This is nasty workaround. First you create QSettings, then get it's location.

QSettings cfg(QSettings::IniFormat, QSettings::UserScope, "organization", "application");
QString config_dir = QFileInfo(cfg.fileName()).absolutePath() + "/";

Credits goes to Qt Centre forum

Edit: QSettings stores default config in user AppData directory. See documentation for QSettings. Also this code instructs to store config in Ini file format.

Pavels