I started learning the QT
toolkit today and attempting to run a small test came across a question: How do I convert an integer to QString
?
Is there a function that takes an integer and returns an object of type QString
?
I started learning the QT
toolkit today and attempting to run a small test came across a question: How do I convert an integer to QString
?
Is there a function that takes an integer and returns an object of type QString
?
One of the most positive aspects of this framework is its extensive documentation. Even today, I always have the API page open to clarifying the simplest questions. I highly recommend your reading to anyone who wants to start developing software using this toolkit.
Now, and answering your question. To convert an integer to an object of type QString
you can use the QString :: number () ; This method returns an object of type QString
equivalent to the number and according to the base passed as parameter. By default, the base is 10 but the method accepts values between 2 and 36.
int i = 42;
QString s = QString::number(i);
Another alternative is the QString :: setNum () method. The difference to the previous one is that it does not creates a new object by changing only the instance in which it is applied. For example:
QString str;
str.setNum(1234); // str == "1234"