[Solved] Problem with QSetting
-
Where is database.ini located ?
-
[quote author="SGaist" date="1398287969"]Where is database.ini located ?[/quote]
No specific path !
I can write into this ini file with below code :
QSettings settings("database.ini", QSettings::IniFormat);
settings.setValue("Server", "192.168.1.1");but for read.... I don't know why doesn't work.
-
Just a wild idea:
try with foo in place of General for the group name
-
[quote author="SGaist" date="1398288372"]Just a wild idea:
try with foo in place of General for the group name [/quote]
Can you show me with example ? :)
-
Before that, just saw something:
@
QSettings settings(“database.ini”, QSettings::IniFormat); settings.setValue(“Server”, “192.168.1.1”);
@You don't begin the group, is that a missing line ?
-
[quote author="SGaist" date="1398289288"]Before that, just saw something:
@
QSettings settings(“database.ini”, QSettings::IniFormat); settings.setValue(“Server”, “192.168.1.1”);
@You don't begin the group, is that a missing line ?[/quote]
but this is not for Read from ini file ! I don't have problem with setValue :)
My main problem is reading from file :(You just show me how can I read from ini file , maybe I have a little mistake.
Of course my ini file content is :[General]
Server=192.168.1.1Why I can't read 192.168.1.1 from server!?
-
The thing is: your writing to the init file and your reading must match.
Using :@
QSettings settings(“database.ini”, QSettings::IniFormat); settings.setValue(“Server”, “192.168.1.1”);
@to write, then you must use
@
QSettings settings(“database.ini”, QSettings::IniFormat);
QString server = settings.value(“Server”, “”).toString();
@to read it back
[edit: corrected my code]
-
No ! error... in QString server = settings.value(“Server”, “”);
I changed it to below format with QVariant
@
QSettings settings("database.ini", QSettings::IniFormat);
QVariant server = settings.value("Server", "");qDebug() << "Server = " << server.toString();
@Result is :
Server = "192.168.1.1"
Good work :)
Thank you very much. ;) -
You're welcome !
Since you have your settings working now, please update the thread title prepending [solved] so other forum users may know a solution has been found :)
-
Yes of course !
title is changed :)