tags:

views:

126

answers:

4

Hey guys .. Just a simple question .. Is there an QString function which takes and int and outputs its QString form ?

+6  A: 

Use QString::number():

int i = 42;
QString s = QString::number(i);
Georg Fritzsche
+2  A: 

In it's simplest form, use the answer of Georg Fritzsche

For a bit advanced, you can use this,

QString QString::arg ( int a, int fieldWidth = 0, int base = 10, const QChar & fillChar = QLatin1Char( ' ' ) ) const

Get the documentation and an example here..

liaK
+1  A: 

And if you want to put it into string within some context, forget about + operator. Simply do:

int i = 13; QString printable = QString("My magic number is %1. That's all!").arg(i)

Kamil Klimek
Very useful method! +1 for that.
Narek
A: 

I always use QString::setNum().

int i = 10;
double d = 10.75;
QString str;
str.setNum(i);
str.setNum(d);

setNum() is overloaded in many ways. See QString class reference.

Narek