QSettings - where is the location of the ini file?

Viewed 60806

I'm using QSettings to store some data as ini file in Windows. I want to see the ini file, but I don't know what is the location of the ini file.

This is my code:

QSettings *set = new QSettings(QSettings::IniFormat, QSettings::UserScope, "bbb", "aaa");
set->setValue("size", size());
set->setValue("pos", pos());

Where do I have to look? Or may be I miss the code which write it to the file? When does the QSettings write its values?

9 Answers

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.

In linux you can use this snippet or insert this lines into your main code for find location of your file with python.

from PyQt5.QtCore import QSettings

settings = QSettings("Organization Name", "App name")
print(QSettings.fileName(settings))

It should return an output like this.

/$HOME/.config/Organization Name/App name.conf

Source

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

On Windows without providing an ini filename, you'll find the data in the registry. Using this code snippet:

    int red = color.red();
    int green = color.green();
    int blue = color.blue();
    QSettings settings("Joe", "SettingsDemo");
    qDebug() << settings.fileName();
    settings.beginGroup("ButtonColor");
    settings.setValue("button1r", red);
    settings.setValue("button1g", green);
    settings.setValue("button1b", blue);
    settings.endGroup();

After running this code, you'll see the output:

"\\HKEY_CURRENT_USER\\Software\\Joe\\SettingsDemo"

Now, opening the regedit tool and following the path list you got: 1

Related