首页 > 编程知识 正文

arg函数怎么算,arg是什么函数怎么算

时间:2023-05-05 23:10:35 阅读:59576 作者:673

QString的arg (方法

在QT的QString中,arg方法类似于c的printf中使用的格式输出符。 但是,有点相似。

有三种方法:

用arg(str1、str2、str3)的方法置换。

用以下方法替换: arg(str1).arg(str1).arg(str1)。

用arg(int,int,int )的方式置换。

1 )使用arg(str1、str2、str3)和arg(str1).arg(str1).arg(str1)

函数原型:

qtringarg(constqstringA1,const QString a2,const QString a3,const QString a4,const QString a5,const QString a6,const qstring al qstring str=qstring (' %1%2%3%4%5%6%7%8%9).arg )、'2'、'3'、'4'、'5'和' str输出为' 123456789

qstring str=qstring (' %1%2%3%4%5%6%7%8%9).arg )、'2'、'3'、'4'、' w '、'6'和'7' str输出为

看看这两种方法的区别。

str=QString('%1 %2' ).arg('%1World ',' Hello '; 输出str为“% 1世界帮助”,对应于顺序

str=qstring(%1%2).arg ) %1world ).arg ) Hello ); 输出str为“HelloWorld %2”;

这是因为第一个arg运行后将成为qstring(“%1world%2”).arg (“hello”),然后运行第二个。

请注意以下示例:

str=qstring(%1%2).arg ) %1world ).arg ) Hello ); //输出: ' Helloworld%2'str=qstring(%1%2) ).arg ) ) %2world ).arg ) Hello ) ); //输出: ' Hello world hello ' str=qstring (' %1%2) ).arg ) ) %3world ).arg ) ) hello ) ); //输出: ' %3worldhello'str=qstring(%1%2) ).arg ) ) %8world ).arg ) hello ); //输出: ' %8worldhello'str=qstring(%1%6) )、arg )、' %3world )、arg )、hello ); //输出: ' Helloworld%6'str=qstring(%2%6) )、arg )、' %3world )、) arg )、Hello ); //输出: ' Helloworld%6'str=qstring(%0%6) ).arg ) ) %3world ).arg ) Hello ) ); //输出: ' Helloworld%6'str=qstring(%-1%6) ).arg ) ) %3world ).arg ) Hello ) ); //输出:使用' %-1 HelloWorld' 2) arg(int,int )

函数的原型如下:

qtringarg(inta,int fieldWidth=0,int base=10,QChar fillChar=QLatin1Char (' ' ) const Q_REQUIRED_RESULT; a :表示要处理数字的fieldWidth :字宽; 基本:数字基数、

如下所示。 str=qstring (十进制63的十进制是%1) ).arg ) 63,0,10 ); //输出:“十进制63的十进制是63(str=qstring;十进制63的十六进制是%1) ).arg ) 63、0、16 );

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。