分享

如何使用QString::arg()

 666江大大大 2017-06-29

如何使用QString::arg()

在Qt Asistant中,QString::arg的定义如下:

  1. QString QString::arg ( const QString & a, int fieldWidth = 0, const QChar & fillChar = QLatin1Char( ' ' ) ) const  

功能介绍如下:
Returns a copy of this string with the lowest numbered place marker replaced by string a, i.e., %1%2, ..., %99.

给出的例子如下:
  1. QString i;           // current file's number  
  2.      QString total;       // number of files to process  
  3.      QString fileName;    // current file's name  
  4.   
  5.      QString status = QString("Processing file %1 of %2: %3")  
  6.                      .arg(i).arg(total).arg(fileName);  
  7. First, arg(i) replaces %1. Then arg(total) replaces %2. Finally, arg(fileName) replaces %3.  

下面,我给出具体例子:

  1. QString i = "5";           // current file's number  
  2. QString total = "10";       // number of files to process  
  3. QString fileName = "lyc.txt";    // current file's name  
  4.   
  5. QString status = QString("Processing file %1 of %2: %3")  
  6.     .arg(i).arg(total).arg(fileName);  
  7.   
  8. qDebug() << "status: " << status;  

输出结果如下:

  1. status:  "Processing file 5 of 10: lyc.txt"   



http://blog.csdn.net/lyc_daniel/article/details/9260197

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多