[SOLVED]How to write values in a existing .ini file
-
wrote on 20 Jul 2014, 12:46 last edited by
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
-
wrote on 20 Jul 2014, 13:43 last edited by
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:
[/quote]
Description for "setValue":http://qt-project.org/doc/qt-5/qsettings.html#setValue -
wrote on 20 Jul 2014, 22:26 last edited by
@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
[SOLVED] -
wrote on 23 Jul 2014, 08:01 last edited by
Hello, is there another way to R/W in INI files rather than QSetting ?
thnx -
wrote on 23 Jul 2014, 11:11 last edited by
[quote author="AbdelAli" date="1406102515"]Hello, is there another way to R/W in INI files rather than QSetting ?
thnx[/quote]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.
-
wrote on 23 Jul 2014, 13:25 last edited by
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
-
wrote on 23 Jul 2014, 21:10 last edited by
Thank you MuldR, I finished by using QSettings, it's the simplest way to do it,
2/7