qtqstringqt4.7

Appending number to QString with arg() , is there better ways?


I've been using QString::number () to convert numbers to string for long time , now i'm wondering if there's something better than following:

  int i = 0;
  QString msg = QString ("Loading %1").arg (QString::number (i));

How can i spare QString::number () ? i checked document , seems only "%1" is applicable , no other stuff like "%d" could work


Solution

  • You can directly use arg() like this

    int i = 0;
    QString msg = QString ("Loading %1").arg(i);
    

    Qt will automatically convert it for you