QSettings rewriting the .ini file, so not able to restore the values

924 views Asked by At

When I am using below code on Linux SLES 11 machine the .ini file is recreating for some reason so that I am not able to restore my settings.

Same code working fine on Windows machine.

Prb: I want to have recently opened file list on start up window, so that user can select quickly.

void Window::saveRecentFileList()
{
    QSettings settings(m_settingsPath, QSettings::NativeFormat);
    settings.setValue("recentFiles/list", QVariant(m_recentFilesList));
}

void Window::restoreRecentFileList()
{
    QSettings settings(m_settingsPath, QSettings::NativeFormat);
    m_recentFilesList = settings.value("recentFiles/list").toStringList();
}
1

There are 1 answers

0
Andrew Dolby On

Try using QSettings::IniFormat instead of QSettings::NativeFormat. On Windows, you should be using QSettings::IniFormat anyways with a specific ini file location. Linux uses ini files as its native format for settings storage, but the QSettings documentation suggests that:

On all platforms, if you want to read an INI file directly, you can use the QSettings constructor that takes a file name as first argument and pass QSettings::IniFormat as second argument.