PDA

View Full Version : Escaping %1 with QString::arg()



marcvanriet
20th January 2011, 01:19
Hi,

I'm using QString::arg() to fill in data in a string.

Unfortunately, my string contains also the text "%1" that must appear in the output unchanged.

Is there a way to escape the %n when using .arg() ?

Best regards,
Marc

wysota
20th January 2011, 01:29
Have you tried escaping the % character with another % character?

Zlatomir
20th January 2011, 01:38
Something like this should work:

for(int i =0; i <10; i++){
qDebug() << QString("String % 1, no %1").arg(i).replace("% 1", "%1");
}