Call to member function 'arg' is ambiguous.
-
Hello citizens!
With this simple code I get the error: Call to member function 'arg' is ambiguous.uint lng_abs = 3425; QString lngFormatted = QString("%1").arg(lng_abs, 3, 10, '0');
But arg function has definition with uint argument:
QString QString::arg(uint a, int fieldWidth = 0, int base = 10, QChar fillChar = u' ') const
At the same time I don't get the error using arg in the following way:
QString lngFormatted = QString("%1").arg(lng_abs, 3);
I could use
arg(QString::number(lng_abs).rightJustified(3, '0'))
in the first case, but for my better understanding, can you explain please, how to fix the first code example to use arg with all arguments?
And why is 'arg' ambiguous, if I give it uint argument and arg has uint prototype?Thank you in advance!
-
@JonB
It indicates that there are other arg functions with different arguments, but is there a way to use a uint function and don't get the warning? Because I passed all arguments according to the declaration:QString QString::arg(uint a, int fieldWidth = 0, int base = 10, QChar fillChar = u' ') const
and still get the warning. -
Hello citizens!
With this simple code I get the error: Call to member function 'arg' is ambiguous.uint lng_abs = 3425; QString lngFormatted = QString("%1").arg(lng_abs, 3, 10, '0');
But arg function has definition with uint argument:
QString QString::arg(uint a, int fieldWidth = 0, int base = 10, QChar fillChar = u' ') const
At the same time I don't get the error using arg in the following way:
QString lngFormatted = QString("%1").arg(lng_abs, 3);
I could use
arg(QString::number(lng_abs).rightJustified(3, '0'))
in the first case, but for my better understanding, can you explain please, how to fix the first code example to use arg with all arguments?
And why is 'arg' ambiguous, if I give it uint argument and arg has uint prototype?Thank you in advance!
@Atr0p0s
There will be another overload which it could also match. When you get that error message, does the compiler output more lines of information indicating which ones match? My gcc does, and lets you see what all the alternatives are so that you can adjust to be precise, e.g. first line of several:/home/jon/QtTests/proxy/main.cpp:177: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second: main.cpp: In function ‘int main(int, char**)’: main.cpp:177:45: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second: 177 | QString lngFormatted = QString("%1").arg(lng_abs, 3, 10, '0'); | ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
-
@Atr0p0s
There will be another overload which it could also match. When you get that error message, does the compiler output more lines of information indicating which ones match? My gcc does, and lets you see what all the alternatives are so that you can adjust to be precise, e.g. first line of several:/home/jon/QtTests/proxy/main.cpp:177: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second: main.cpp: In function ‘int main(int, char**)’: main.cpp:177:45: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second: 177 | QString lngFormatted = QString("%1").arg(lng_abs, 3, 10, '0'); | ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
@JonB
It indicates that there are other arg functions with different arguments, but is there a way to use a uint function and don't get the warning? Because I passed all arguments according to the declaration:QString QString::arg(uint a, int fieldWidth = 0, int base = 10, QChar fillChar = u' ') const
and still get the warning. -
@JonB
It indicates that there are other arg functions with different arguments, but is there a way to use a uint function and don't get the warning? Because I passed all arguments according to the declaration:QString QString::arg(uint a, int fieldWidth = 0, int base = 10, QChar fillChar = u' ') const
and still get the warning.@Atr0p0s said in Call to member function 'arg' is ambiguous.:
Because I passed all arguments according to the declaration: QString QString::arg(uint a, int fieldWidth = 0, int base = 10, QChar fillChar = u' ') const and still get the warning.
But, did you really, or do you thing you did? :P
go the full way:
QString lngFormatted = QString("%1").arg(lng_abs, 3, 10, QChar('0'));
-
@JonB
It indicates that there are other arg functions with different arguments, but is there a way to use a uint function and don't get the warning? Because I passed all arguments according to the declaration:QString QString::arg(uint a, int fieldWidth = 0, int base = 10, QChar fillChar = u' ') const
and still get the warning. -
@Atr0p0s
As @J-Hilk says. Explanation in https://www.qtcentre.org/threads/62640-Bug-Issue-compiler-is-confused-with-calling-simple-arg(int-int-int-QChar)-func- [our own @ChrisW67 :) ] -
@Atr0p0s said in Call to member function 'arg' is ambiguous.:
Because I passed all arguments according to the declaration: QString QString::arg(uint a, int fieldWidth = 0, int base = 10, QChar fillChar = u' ') const and still get the warning.
But, did you really, or do you thing you did? :P
go the full way:
QString lngFormatted = QString("%1").arg(lng_abs, 3, 10, QChar('0'));
-
A Atr0p0s has marked this topic as solved on