qt string内带变量_[转载]Qt 字符串QString arg()用法总结

QString 有多种方法,我慢慢总结中~~~~~~~~~~~~

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

Cpp代码  

QString i ="iTest";// current file's number

QString total ="totalTest";// number of files to process

QString fileName ="fileNameTest";// current file's name

QString status = QString("Processing file %1 of %2: %3")

.arg(i).arg(total).arg(fileName);

style="BACKGROUND-COLOR: #ffffff"> qDebug() <

QString i = "iTest"; // current file's number

QString total = "totalTest"; // number of files to process

QString fileName = "fileNameTest"; // current file's name

QString status = QString("Processing file %1 of %2: %3")

.arg(i).arg(total).arg(fileName);

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代码  

QString str;

str = QString("Decimal 63 is %1 in hexadecimal")

.arg(63, 0, 16);

// str == "Decimal 63 is 3f in hexadecimal"

QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedStates));

str = QString("%1 %L2 %L3")

.arg(12345)

.arg(12345)

.arg(12345, 0, 16);

// str == "12345 12,345 3039"

//16进制显示,就忽略%L3的L

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值