加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

Qt 字符串QString arg()用法总结

(2017-02-27 17:21:44)
分类: QT开发
转自:Qt 字符串QString arg()用法总结

1、QString::arg()//用字符串变量参数依次替代字符串中最小数值

 

 

 

Cpp代码  http://qimo601.iteye.com/images/icon_star.png字符串QString arg()用法总结" />
  1. QString "iTest"          // current file's number  
  2. QString total "totalTest"      // number of files to process  
  3. QString fileName "fileNameTest"   // current file's name  
  4.   
  5. QString status QString("Processing file %1 of %2: %3" 
  6.                 .arg(i).arg(total).arg(fileName);  
  7.  style="background-color: #ffffff;"    qDebug() << status ;  

 结果就是:"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

 

     16进制输出:fieldWidth表示字符宽度,base表示进制,

 

Cpp代码  http://qimo601.iteye.com/images/icon_star.png字符串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.   
  6. QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedStates));  
  7. str QString("%1 %L2 %L3" 
  8.         .arg(12345)  
  9.         .arg(12345)  
  10.         .arg(12345, 0, 16);  
  11. // str == "12345 12,345 3039"  
  12. //16进制显示,就忽略%L3的L  

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有