QSettings - where is the location of the ini file?

倖福魔咒の 提交于 2019-12-02 23:39:06

To print out the exact location of your settings file use method fileName method of QSettings class.

QSettings settings("folderName", "fileName");
qDebug() << settings.fileName();

Console output looks then like:

/home/user/.config/folderName/fileName.conf
Andy M

I think you'll find everything you're looking for here : http://doc.qt.io/archives/qt-4.7/qsettings.html

It's plateform specific, see under :

Platform-Specific Notes Locations Where Application Settings Are Stored

You can store Settings in files as well :

QSettings settings("/home/petra/misc/myapp.ini",
                QSettings::IniFormat);
Jordan

QSettings save location changes to the QSettings.Scope enum. QSettings save to the Local scope by default. On Linux, I found my local settings in:

~/.config/CompanyName/ApplicationName.conf

Jérôme

If you create a QSettings without giving any specific path, the ini file will be located in the application path.

QSettings Settings("myapp.ini", QSettings::IniFormat);
Settings.setValue("Test", "data");

//...
qDebug() << QApplication::applicationDirPath();

Be careful though : the application path might change : for instance, if you are developping your app with Qt Creator, in debug mode, the application path is in the /debug subfolder.

If you are running it in release mode, the application path is in the /release subfolder.

And when your application is deployed, by default, the application path is in the same folder as the executable (at least for Windows).

Check out the QStandardPaths class, it links to multiple standard paths including configuration on all supported platforms. https://doc.qt.io/qt-5/qstandardpaths.html

QT >= 5.5:

QString path = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);

QT < 5.5:

QString path = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation);

There are paths for config files in shared config directories, application data directories, and more.

On Mac OSX, I found the file under at ~/Library/Preferences

The QSettings class provides persistent platform-independent application settings. Users normally expect an application to remember its settings (window sizes and positions, options, etc.) across sessions. This information is often stored in the system registry on Windows, and in XML preferences files on Mac OS X. On Unix systems, in the absence of a standard, many applications (including the KDE applications) use INI text files

http://doc.qt.io/archives/qt-4.7/qsettings.html

in windows path is like below: C:\Users\user_name\AppData\Roaming\bbb

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!