PDA

View Full Version : Pass a float value to a string



alitoh
11th April 2011, 13:57
I need to pass the float value of an objects property to a string, which is another property of that same object, so that it can be printed in by the painter.

The thing is, I have no idea how to either:

a)Convert a float to a string.
b)Pass a float as a parameter to a string.

I tried googling first but, surprisingly, no useful answers have shown up. (Maybe I'm searching with the wrong keywords).

Can I get any insight into this? Thanks in advance.

Gokulnathvc
11th April 2011, 13:59
float val = 12.0;
QString str = QString::number(val);

stampede
11th April 2011, 14:34
You can also use QString::arg (http://doc.qt.nokia.com/latest/qstring.html#arg-20).

viulskiez
11th April 2011, 17:38
Just share. QVariant is also usefull for convertions, but in this case it's better to use QString::number() or QString::arg().