Kelvin Salton Kelvin Salton - 2 months ago 17
Ini Question

How to store INI files using QSettings on OS X

I'm using

QSettings
to store some settings of my application in a INI file.

On Windows everything works fine and my INI file is stored in the same folder of my application. But on OS X I can't find the INI file, and the settings are not loaded when I open my application again.

I'm using the following code to store the values in the INI file using
QSettings
:

QSettings *settings = new QSettings("settings.ini", QSettings::IniFormat);

settings->beginGroup("AppSettings");
settings->setValue("Language", language);
settings->endGroup();


Does anybody knows what is happening?

How can I store INI files inside my Application.app on OS X?

Answer

I think the OS X does not gives permissions to edit files inside the app bundle.

I solved the problem by changing the INI file location:

QString path = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation);
QSettings *settings = new QSettings(path+"/settings.ini", QSettings::IniFormat);

settings->beginGroup("AppSettings");
settings->setValue("Language", language);
settings->endGroup();

Now the INI file will be saved in the QStandardPaths::ConfigLocation location, that in my case is /Users/.../Library/Preferences

I solved the problem based on this topic.

Comments