PDA

View Full Version : qstringlist array crashes program



chrisb123
23rd October 2009, 12:06
Can someone explain this
This works


QString usage = "12.34 56.78";
QStringList usage2 = usage.split(" ");
foreach (QString str, usage2) {
qDebug() << str;
}
This works

float used = usage2[0].toFloat();

This does not work

float used = usage2[1].toFloat();

jano_alex_es
23rd October 2009, 12:10
seems like usage2 is rewritten somewhere

scascio
23rd October 2009, 13:32
I tested the code provided and it worked.

So the error is not coming from these instructions

wysota
23rd October 2009, 14:13
The space character is probably not the space character but some other whitespace.

chrisb123
23rd October 2009, 15:03
here is a bit more information
my programming skills are bad so there is probably a fundamental error somewhere, porbably in the header file but...
a timer calls a public slot function "update" which reads a file containining a single line of data and assings it to usage
if i extract the data from usage in this function I can use
if i extract this data elsewhere it crashes
.... hmmm just sovlved the problem

The reason was the variable was empty, I just needed to call the function first