Qt4.4 how to get the user settings path


Question

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

It can be set using http://qt-project.org/doc/qt-4.8/qsettings.html#setPath, but it seems as I am not able to retrieve it.

http://qt-project.org/doc/qt-4.8/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)

1
18
11/16/2013 9:00:50 PM

Accepted Answer

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?

20
11/16/2013 9:02:38 PM

This is a nasty workaround. First you create QSettings, then get its location.

QSettings cfg(QSettings::IniFormat, QSettings::UserScope,
       "organization", "application");

QString config_dir = QFileInfo(cfg.fileName()).absolutePath() + "/";

Credits go to the Qt Centre forum.

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


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon