How to deal with “%1” in the argument of QString::arg()?

天大地大妈咪最大 提交于 2019-11-28 21:18:49
Johnny

See the Qt docs about QString::arg():

QString str;
str = "%1 %2";
str.arg("%1f", "Hello"); // returns "%1f Hello"

Note that the arg() overload for multiple arguments only takes QString. In case not all the arguments are QStrings, you could change the order of the placeholders in the format string:

QString("1%1 2%2 3%3 4%4").arg(int1).arg(string2).arg(string3).arg(int4);

becomes

QString("1%1 2%3 3%4 4%2").arg(int1).arg(int4).arg(string2, string3);

That way, everything that is not a string is replaced first, and then all the strings are replaced at the same time.

user2665241

You should try using

QString("%1-%2").arg("%2","foo");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!