PDA

View Full Version : qstring extraction



mickey
17th July 2006, 21:21
hi I need put the col nu,ber inside f; this is working; is there a better way? (eg more fast) thanks


QString col = "1 1.5 0.5 1";
float f[4];
for (int i=1; i <= col.length(); i++) {
int p=0;
if (col.at(i) == ' ') {
QString c = QString::fromAscii(col,i);
f[p] = c.toFloat();
p++;
}
}

jpn
17th July 2006, 21:37
QString col = "1 1.5 0.5 1";
QTextStream stream(&col);
float f[4];
for (int i = 0; i < 4; ++i)
stream >> f[i];

jacek
17th July 2006, 21:39
is there a better way? (eg more fast) thanks
I don't know if it's faster, but certainly a lot clearer:
QStringList values( QStringList::split( ' ', col ) );
for( int i = 0; i < values.size(); ++i ) {
f[ i ] = values[ i ].toFloat();
}

mickey
17th July 2006, 23:14
thanks. mine is bugged....I don't know where...