Solved call of overloaded replace(char,char, QT::CaseSensitivity) is ambiguous
-
Hi, the statement:
tokFormula = tokFormula.replace('+','-',Qt::CaseInsensitive);I got a warning:
call of overloaded replace(char,char, QT::CaseSensitivity) is ambiguous.
If I change the statement to:
tokFormula = tokFormula.replace("+","-",Qt::CaseInsensitive);
then it works well.But in QT document:
QString &QString::replace(QChar before, QChar after, Qt::CaseSensitivity cs = Qt::CaseSensitive)
This function overloads replace().
Replaces every occurrence of the character before with the character after and returns a reference to this string. -
Hi @samzhcs1,
call of overloaded replace(char,char, QT::CaseSensitivity) is ambiguous.
At a glance, I'd say the reason this is ambiguous is because there is no
QString::replace
overload that takeschar
- you're probably expecting the overload that takesQChar
(which is notchar
) but the compiler cannot make that assumption.Put another way, the compiler could just as validly turn your
char
arguments intoQChar
orQString
- obviously we can tell from the names that you probably wantQChar
, but the compiler doesn't know this.So, try converting your
char
argument toQChar
explicitly, like:myString.replace(QChar(char1), QChar(char2), ...);
Cheers.