Important: Please read the Qt Code of Conduct -

QSettings doesn't create the INI file

  • I use the QSettings class to read an INI file and I'd like to let it create the file with default values if it doesn't exists (as it should do), but, it seems to doesn't work.

    This is the code I use:
    _m_pInstance = new QSettings(QDir::currentPath() + SETTINGS_FILE_NAME, QSettings::IniFormat, NULL);


    m_strMainFrm1IpAddr = m_pInstance->value(MAINFRAME1_IP_ADDR_KEY, DEF_MAINFRM1_IP_ADDR).toString();

    If the file doesn't exist, my variable is updated with the default value but the INI file is non created.

    What's wrong ?
    Are there other calls to do ? Is it due to the dynamical allocation of the QSettings Class ?

    Edit: Please surround code sections with @ tags for readability; Andre

  • The default value you pass to the value() function only concerns the return value of the function. As you can see, it's a const function, it doesn't change anything on the QSettings object. If you want to write to the QSettings object, use setValue().

  • Hi,

    I think sync() will write to file only if you used QSettings::setValue(). Reading values does not change file, so sync() does not need to write it.

Log in to reply