How to append a Qstring using "%" operand

append, c++, qstring

Solution

Try this:

double d1 = 0.5,d2 = 30.0
QString str  = "abc";
str.append(QString("%1").arg(d1));
str.append(" def ");
str.append(QString("%1").arg(d2));

[EDITED] The point is, the "arg" is a method of a class QString and must be used with an instance of it. In your not-working example you don't do this.

Problem

I am trying to `.append` my QString with two `double` values using the `%` operand. I saw the following example in the QString class reference documentation for using `arg` with double, but the example doesn't include appending the str: ``` double d = 12.34; QString str = QString("delta: %1").arg(d); ``` here is my code. it does not include any run-time error but it doesn't place my doubles where the `%` operand is, instead it include my %1 and %2 as normal strings too: ``` double d1 = 0.5,d2 = 30.0 QString str = "abc"; str.append("%1 def %2").arg(d1).arg(d2); ``` thank you

Original source