Can tell me why the code below causes this error :
call of overloaded 'QChar(const char[2])' is ambiguous
and the code :
void func(QChar a) {
qDebug() << a;
}
void main() {
func(" ");
}
When String.remove(QChar,Qt::Ca开发者_开发知识库seSensitive)
works : a.remove(" ");
You're passing a string literal (" "
), which is of type const char[2]
(one element containing the space, and another one for the terminating \0
). You want to pass a char literal, written with single quotes: func(' ')
.
The QString::remove()
function is overloaded for both strings and single characters. Even in that case, you want to pass a char literal ' '
, which is more efficient than " "
(the latter implies a call to strlen()
).
Try to write
void main() {
func(' ');
}
Seems like compiler thinks that you passing const char*
not a char
because of double quotes.
And there is no constructor for QChar
from const char*
.
精彩评论