Qt 字符串QString arg()用法总结
2014-05-28 22:37
288 查看
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() << 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
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
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() << 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
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
相关文章推荐
- Qt 字符串QString arg()用法总结
- Qt 字符串QString arg()用法总结
- Qt字符串特殊用法总结
- 【总结】ASP字符串转换函数用法
- QT QTableWidget 用法总结
- QT QTableWidget 用法总结
- Qt中QTableWidget用法总结
- QT QTableWidget 用法总结
- string字符串用法总结
- Qt开发中字符串、字节数组和变量常用的一些函数总结
- 字符串用法总结
- Qt QTableWidget用法的一些小总结
- C/C++(字符串处理)字符指针、字符数组用法大总结
- QT QTableWidget 用法总结
- .Net配置文件中数据库中连接字符串用法总结
- QT QTableWidget 用法总结(转)
- JS字符串用法总结
- QT QTableWidget 用法总结
- 【转】QT QTableWidget 用法总结
- Qt开发中字符串、字节数组和变量常用的一些函数总结