November 26, 2011

samlion007 samlion007
Lab Rat
14 posts

How i can convert int to QString

 

I maked my function to convert int to QString like:

  1. QString convertInt(int number)
  2. {
  3.     if (number == 0)
  4.         return "0";
  5.     QString temp="";
  6.     QString returnvalue="";
  7.     while (number>0)
  8.     {
  9.         temp+=number+48;
  10.         number/=10;
  11.     }
  12.     for (int i=0;i<temp.length();i++)
  13.         returnvalue+=temp[temp.length()-i-1];
  14.     return returnvalue;
  15. }

my quis. is there any function more easy then this.

Thanks

[EDIT: code formatting, please wrap in @-tags, Volker]

2 replies

November 27, 2011

Scylla Scylla
Lab Rat
238 posts

1. QString tmp = QString::number(myInt)
2. QString tmp = tr(”%1”).arg(myInt)

November 27, 2011

samlion007 samlion007
Lab Rat
14 posts

Thank you so much,it works

 
  ‹‹ Multithreaded multi-MDI app      the opengl window only flashes........ ››

You must log in to post a reply. Not a member yet? Register here!