I am saving app data in Ini file. Here is how:
QSettings IniFile(K_COMPNAME,K_INIFILENAME);
QSettings::setDefaultFormat(QSettings::IniFormat);
IniFile.setValue("Location",loc);
IniFile.setValue("BaudRate",baud);
IniFile.sync();
K_INIFILENAME is a constant "Settings".
I would expect a Settings.ini in same folder as my exe.
But no. Instead this is saved in Registry. Cause when I do
qDebug() << IniFile.fileName();
it returns:
"\HKEY_CURRENT_USER\Software\MyCompany\Settings"
My question is why is it so, and how to make it save in Ini file.
keep in mind that with constructor:
QSettings IniFile(K_COMPNAME,K_INIFILENAME);
Constructs a QSettings object for accessing settings of the application called application from the organization called organization,
The scope is set to QSettings::UserScope, and the format is set to QSettings::NativeFormat (i.e. calling setDefaultFormat() before calling this constructor has no effect).
Which means its a registry valid constructor (under windows) .. The right approach for INI format would be:
QCoreApplication::setOrganizationName(K_COMPNAME);
QCoreApplication::setApplicationName(K_INIFILENAME);
QSettings::setDefaultFormat(QSettings::IniFormat);
QSettings IniFile;
The above code will use INI format and the settings are stored in FOLDERID_RoamingAppData
For example: FOLDERID_RoamingAppData\<K_COMPNAME>\<K_INIFILENAME>
now there is only one another constructor to store in local INI (settings.ini
) file like this:
QSettings IniFile(K_INIFILENAME,QSettings::IniFormat);