天天看點

Qt 字元串QString arg()用法總結

1、QString::arg()//用字元串變量參數依次替代字元串中最小數值

Cpp代碼  

Qt 字元串QString arg()用法總結

  1. QString i = "iTest";           // current file's number  
  2. QString total = "totalTest";       // number of files to process  
  3. QString fileName = "fileNameTest";    // current file's name  
  4. QString status = QString("Processing file %1 of %2: %3")  
  5.                 .arg(i).arg(total).arg(fileName);  
  6.  style="background-color: #ffffff;">     qDebug() << status ;</span>  

 結果就是:"Processing file iTest of totalTest: fileNameTest"

First, arg(i) replaces %1. Then arg(total) replaces %2. Finally, arg(fileName) replaces %3.

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

Qt 字元串QString arg()用法總結
  1. QString str;  
  2. str = QString("Decimal 63 is %1 in hexadecimal")  
  3.         .arg(63, 0, 16);  
  4. // str == "Decimal 63 is 3f in hexadecimal"  
  5. QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedStates));  
  6. str = QString("%1 %L2 %L3")  
  7.         .arg(12345)  
  8.         .arg(12345, 0, 16);  
  9. // str == "12345 12,345 3039"  
  10. //16進制顯示,就忽略%L3的L  

繼續閱讀