You get that when you try to compile the code because this:
QString test_str = QString("20%1").arg(5, 2, 10, '0');
To copy to clipboard, switch view to plain text mode
matches several possibilities (which your compiler listed for you). For example:
QString arg
(double a,
int fieldWidth
= 0,
char format
= 'g',
int precision
= -1,
QChar fillChar
= QLatin1Char( ' ' )) const
QString arg(double a, int fieldWidth = 0, char format = 'g', int precision = -1, QChar fillChar = QLatin1Char( ' ' )) const
QString arg(short int a, int fieldWidth = 0, int base = 10, QChar fillChar = QLatin1Char( ' ' )) const
To copy to clipboard, switch view to plain text mode
5 can be implicitly cast to double or short int to fit either prototype.
2 is an int and matches both perfectly.
10 is an int but can be implicitly cast to char to fit the other prototype. It is an invalid format letter but the compiler cannot know that.
'0' is a char but can be implicitly cast to either int or QChar to match either prototype.
The last argument in the first prototype has a default.
So, your call could match either prototype and the compiler warns that C++ standard says these are ambiguous. However, the compiler has chosen one of the options using a heuristic (the double variant on my machine, probably because cast of an int to short might lose information) but it may not be the one you expected.
Specifying QChar('0') as the last argument eliminates the first option (a QChar cannot be cast to int).
Bookmarks