PDA

View Full Version : (Solved) Reading value from INI



WijbeCT
21st November 2009, 10:01
Hello,

Just starting with QT and now have a little problem and don't have a solution:

A INI-file have the next value: "123,4 Ab" and I want this value in a QLabel.
Because of the "," it is not possible, how can I handle this?:confused:


QSettings settings ("log.ini", QSettings::IniFormat);
settings.beginGroup("group");
QString ruuun = settings.value("value", "Nothing").toString(); // value set in ruuun
ui->settings->setText(ruuun); // Nothing displayed because of the ","

wysota
21st November 2009, 11:54
The comma should have nothing to do with this. How does your ini file look like exactly? What is the exact (compilable) code to reproduce the problem?

cae
21st November 2009, 11:55
i don't know a good solution, but i know one...

you can read the number in two times with



a=line.section(",",0,0).toInt()
b=line.section(",",1,1).toInt()

a = a + b/10



this is only an idea, you should check how many numbers after the symbol , and divide it those times by 10.

If you dont find any other solution... try this xD

wysota
21st November 2009, 12:06
But he wants it as text, why should he convert it back and forth from integers?

cae
21st November 2009, 12:15
ohhh i missed that part!! :p

then... i cant see the problem there.

WijbeCT
21st November 2009, 12:44
The comma should have nothing to do with this. How does your ini file look like exactly? What is the exact (compilable) code to reproduce the problem?


I have tested the value by chancing the "," in "." and the value is displaying, rechancing in a "," and the value is not displaying....


INI:
[file]
run=Woensdag 18 september 2009
cleaning=158,9 Mb verwijderd

The code is the "same" as the snippet (only with the value of run and some text).

Is this not to reproduce(?), after a restart from my computer, for me the problem is the same! I'm working in Qt Creator, maybe that's the reason

wysota
21st November 2009, 13:16
Without quotes the value is treated as a list of strings. Either wrap the value in quotes or convert the variant to a string list.

WijbeCT
21st November 2009, 15:53
Because of the comma in the value (Qt wants to) handle this as a StringList:



QString ruuun = settings.value("value", "Nothing").toString(); // value set in ruuun


chanced in:



QStringList ruuun = settings.value("value", "Nothing").toStringList();


after that, replaced the ",".

Thanks to "wysota" for showing me this way.:)

wysota
21st November 2009, 21:46
Thanks to "wysota" for showing me this way.:)

You don't have to put my name in quotes, there is no comma in it ;)

WijbeCT
22nd November 2009, 05:13
You don't have to put my name in quotes, there is no comma in it

Now I'm sure I can read you "as is". :)