QString(" %1 of %2").arg(...); whats happening?
Solved
General and Desktop
-
I am trying to format 1 or N into a string with:
quint16 uint16Part = 1, uint16Parts = 2; QString strOutput(" Debug:"); strOutput += QString(" %1 of %2").arg(uint16Part, uint16Parts);
The values assigned above are just for demonstration purposes. What I see in strOutput after the last operation is:
" Debug: 1 of %2"
Why? I was expecting:
" Debug: 1 of 2"
-
on the "why": the variants of arg(...) with an int as second argument assume this to be the field width into which the first argument should be fitted into.
For multiple replacements you need all arguments to be QStrings.
Check the documentation: https://doc.qt.io/qt-5/qstring.html#arg-3Regards
Holger