[SOLVED]How to write values in a existing .ini file

  • Hi,

       I have a Line Edit widget in my form and I want to pass the values on a existing .ini file via pushbutton widget. could this be possible? can you give me a sample code for this? TIA

  • Moderators

    From the "documentation":http://qt-project.org/doc/qt-5/QSettings.html
    [quote]QSettings stores settings. Each setting consists of a QString that specifies the setting's name (the key) and a QVariant that stores the data associated with the key. To write a setting, use setValue(). For example:
    Description for "setValue":http://qt-project.org/doc/qt-5/qsettings.html#setValue

  • @void Tools_Settings::on_buttonOk_clicked(){
    QSettings mySettings = new QSettings("existingIniFile.ini", QSettings::IniFormat);
    mySettings->setValue("MainGroup/SubGroup", ui->editMyLineEdit->text());
    hope this will help you
    If this will solve your problem kingdly edit the titple of the main post with

  • Hello, is there another way to R/W in INI files rather than QSetting ?

  • [quote author="AbdelAli" date="1406102515"]Hello, is there another way to R/W in INI files rather than QSetting ?

    INI is a very simple text format. In the easiest case, you can simply use QFile + QTextStream and read the file line by line. Or you can use QFile to append additional lines to the INI file. It becomes slightly more complex though, if you actually need to insert lines or modify existing INI file entries...

    Yet another way of accessing INI files is using the WritePrivateProfileString and GetPrivateProfileString functions. But those are Windows only.

  • Thanks for the inputs unfortunately I haven't tried this because the project that requires this, changed it's specs. But good to know though

  • Thank you MuldR, I finished by using QSettings, it's the simplest way to do it,

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.