Qt QString的arg 方法的使用

2021-08-17 00:12:36 字數 1754 閱讀 8389

(下面兩種方法是比較常用的)

1、qstring的arg()方法用於填充字串中的%1,%2...為給定的引數,如

qstring m = tr("%1:%2:%3").arg("12").arg("60").arg("60");    // m = "12:60:60:
2、它還有另外一種過載方法:

qstring qstring::​arg(int a, int fieldwidth = 0, int base = 10, qchar fillchar = qlatin1char( ' ' )) const

這個方法用於填充字串中的%1,%2...為給定格式的整形數字,其中第乙個引數是要填充的數字,第二個引數為最小寬度,第二個引數為進製,第四個引數為當原始數字長度不足最小寬度時用於填充的字元。

如:

// text = "00123:00456"

qstring text = qstring("%1:%2").arg(123, 5, 10, qchar('0')).arg(456, 5, 10, qchar('0')); 

參考1:

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() <

結果就是:"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 方法的使用

qstring的arg 方法用於填充字串中的 1,2.為給定的引數,如 qstring m tr 1 2 3 arg 12 arg 60 arg 60 m 12 60 60 它還有另外一種過載方法 qstring qstring arg int a,int fieldwidth 0,int base...

Qt QString的arg 方法的使用 一

下面兩種方法是比較常用的 1 qstring的arg 方法用於填充字串中的 1,2.為給定的引數,如 qstring m tr 1 2 3 arg 12 arg 60 arg 60 m 12 60 60 2 它還有另外一種過載方法 qstring qstring arg int a,int fiel...

numpy中arg 方法的應用

numpy中返回物件中最大值,最小值或排序後的索引。arr.argmax 返回array物件中最大值所佔的索引 arr.argmin 返回array物件中最小值所在的索引 arr.argsort 返回array物件中公升序排列後的索引 上述三個api均可填入引數axis 0,1,axis 0,表示按...