4
I started learning Toolkit today QT
and in trying to perform a small test I came across a question: How to convert a whole to QString
?
Is there a function that receives an integer and returns an object of type QString
?
4
I started learning Toolkit today QT
and in trying to perform a small test I came across a question: How to convert a whole to QString
?
Is there a function that receives an integer and returns an object of type QString
?
3
One of the most positive aspects of this framework is its extensive documentation. Even today, I always have the API open to clarify the simplest questions. I highly recommend your reading to those who want to start software development using this Toolkit.
Now and answering your question. To convert an integer into an object of the type QString
you can use the method Qstring::number(); This method returns an object of type QString
equivalent to the number and according to the basis 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 method Qstring::setNum(). The difference to the previous one is that this no creates a new Object by changing only the instance in which it is applied. For example:
QString str;
str.setNum(1234); // str == "1234"
Thanks man! I had heard very well about this community. But I didn’t expect such a quick and complete response. Thanks!
No problem! I advise you to read the tour to better understand how the site works and the community. Welcome!
I wish I could vote on the answer but I don’t seem to have the reputation. :(
Browser other questions tagged qt type-conversion
You are not signed in. Login or sign up in order to post.
Behold here
– ramaral
Thanks @ramaral! Your link leads me to an answer like @Bruno already gave. If your suggestion is the same as his, why not give him a vote, since I can’t. !
– PhatsAndSmall
I voted on your question to help you get enough points so that you can vote in response.
– ramaral
Thank you @ramaral, however I question why I did not vote on the reply. From the little time I spent on the site I noticed that the answers have very few votes in favor. This is yet another example of a good answer that has no votes. The ramaral preferred to present a response exactly like the one that had been accepted, rather than vote. Isn’t that the aim of the community? Reward participants effort? Otherwise what is the incentive to participate?
– PhatsAndSmall
If you notice the date/time of the "poles", will verify that my comment was made before the @Runo response. If the answer had already been given I would not have posted the comment.
– ramaral
I’m sorry, but your comment is posted an hour after the answer. That doesn’t invalidate the fact that I didn’t vote.
– PhatsAndSmall
You’re right, I misread the date. The point is that your question, being the first one you asked on the site, went to an analysis queue where more experienced users check the conformity of the question. That’s when I saw the question and there, in the analysis queue, do not appear the answers given.
– ramaral