原创文章,欢迎转载。转载请注明:转载自 祥的博客
原文链接:https://cloud.tencent.com/developer/article/1596435
函数原型
代码语言:javascript复制QString arg(int a, int fieldWidth = 0, int base = 10, QChar fillChar = QLatin1Char( ' ' )) const
QString arg(uint a, int fieldWidth = 0, int base = 10, QChar fillChar = QLatin1Char( ' ' )) const
QString arg(long a, int fieldWidth = 0, int base = 10, QChar fillChar = QLatin1Char( ' ' )) const
QString arg(ulong a, int fieldWidth = 0, int base = 10, QChar fillChar = QLatin1Char( ' ' )) const
QString arg(qlonglong a, int fieldWidth = 0, int base = 10, QChar fillChar = QLatin1Char( ' ' )) const
QString arg(qulonglong a, int fieldWidth = 0, int base = 10, QChar fillChar = QLatin1Char( ' ' )) const
QString arg(short a, int fieldWidth = 0, int base = 10, QChar fillChar = QLatin1Char( ' ' )) const
QString arg(ushort a, int fieldWidth = 0, int base = 10, QChar fillChar = QLatin1Char( ' ' )) const
QString arg(QChar a, int fieldWidth = 0, QChar fillChar = QLatin1Char( ' ' )) const
QString arg(char a, int fieldWidth = 0, QChar fillChar = QLatin1Char( ' ' )) const
QString arg(double a, int fieldWidth = 0, char format = 'g', int precision = -1, QChar fillChar = QLatin1Char( ' ' )) const
使用实例
代码语言:javascript复制typedef unsigned char uint8;
QString strShowHex,strShowBin;
uint8 val = 0xfc;
//16进制
strShowHex = QString("0x%1").arg(int(val), 4, 16, QLatin1Char('0'));
//显示结果为: 0x00fc
//2进制
strShowBin = QString("%1 b").arg(int(val), 8, 2, QLatin1Char('0'));
//显示结果为: 11111100 b