QString object, very odd behaviour!
-
Hi ALL,
I'm having a very strange behaviour of my QString object. Here my code:
@
//the first line.
QString s;
s= "%1 %2 %3 %4";
s.arg("a").arg("3").arg("0").arg("0");
qDebug() << s.toAscii();//the second line.
QString str;
str = "%1 %2";
str.arg("", "Hello");
qDebug() << str.toAscii();
@The strange is that even though I was waiting for the “3 3 0 0” as answer for the first line and, “ Hello” for the second line in the debug window; I’m receiving “%1 %2 %3 %4” as result of the first line and “%1 %2” as result for the second one. Why I’m having this behaviour? Where is my mistake? behaviour? Where is my mistake?
-
QString::arg() returns copy of string with place marker(s) replaced.
You are printing original string. -
[quote author="Tomma" date="1355740883"]QString::arg() returns copy of string with place marker(s) replaced.
You are printing original string.[/quote]I'm sorry but I didn't understand!
I'm copy the sample got from the QString documentation, here the "link":http://qt-project.org/doc/qt-4.8/qstring.html#arg-2http://. So, please, could you make a sample?
-
Ok...
I understood!It is simple to do this (just for the first line):
@
QString s, msg;
s= "%1 %2 %3 %4";
msg=s.arg("a").arg("3").arg("0").arg("0");
qDebug() << msg;
@ -
thank you for your time!!