'unsigned char' to 'QChar' is ambiguous..but different
-
Hi,
I get the error which is given in the title but something different. I have a project, is quite medium project. I upload this project to the git/github 1-2 week before then I had to remove qt and downgrade qt version for some reason. Whatever it is, now I have one later qt version than the version of I developed this project. (Qt 6.3.1 -> 6.4.0 | QtCreator 8.0.1 -> QtCreator 9.0.1) Now, in the total of the project, I get this error without any changing of a code. How it can be exist? Is there a something anormal in this process? How can I achieve this? I think this error should not be exist.
P.S: In the C:\Qt-> there is a folder, name is 6.3.2 but in the "About QtCreator" Menu; Qt version is 6.4.0
-
@ChrisW67 thanks for the reply. I am not "extremely" know about Qt. How can I do last line of your reply?
@hubeytqew The ambiguity problem is a C++ language one, not Qt.
Modify the line of your code that reads:
text += char_to_add[i];
to read
text += QChar(char_to_add[i]);
-
Hi,
I get the error which is given in the title but something different. I have a project, is quite medium project. I upload this project to the git/github 1-2 week before then I had to remove qt and downgrade qt version for some reason. Whatever it is, now I have one later qt version than the version of I developed this project. (Qt 6.3.1 -> 6.4.0 | QtCreator 8.0.1 -> QtCreator 9.0.1) Now, in the total of the project, I get this error without any changing of a code. How it can be exist? Is there a something anormal in this process? How can I achieve this? I think this error should not be exist.
P.S: In the C:\Qt-> there is a folder, name is 6.3.2 but in the "About QtCreator" Menu; Qt version is 6.4.0
@hubeytqew said in 'unsigned char' to 'QChar' is ambiguous..but different:
How it can be exist?
There was a small change in Qt so this error is now more obvious, fix your code.
-
@hubeytqew said in 'unsigned char' to 'QChar' is ambiguous..but different:
How it can be exist?
There was a small change in Qt so this error is now more obvious, fix your code.
@Christian-Ehrlicher oh the problem its normal..Thanks..
-
Hi,
I get the error which is given in the title but something different. I have a project, is quite medium project. I upload this project to the git/github 1-2 week before then I had to remove qt and downgrade qt version for some reason. Whatever it is, now I have one later qt version than the version of I developed this project. (Qt 6.3.1 -> 6.4.0 | QtCreator 8.0.1 -> QtCreator 9.0.1) Now, in the total of the project, I get this error without any changing of a code. How it can be exist? Is there a something anormal in this process? How can I achieve this? I think this error should not be exist.
P.S: In the C:\Qt-> there is a folder, name is 6.3.2 but in the "About QtCreator" Menu; Qt version is 6.4.0
@hubeytqew said in 'unsigned char' to 'QChar' is ambiguous..but different:
P.S: In the C:\Qt-> there is a folder, name is 6.3.2 but in the "About QtCreator" Menu; Qt version is 6.4.0
I am assuming
C:\Qt
is where you had the online installer drop the various Qt components you are using.The
C:\Qt\Tools
folder contains the Qt Creator version you are running and its own copy of the Qt libraries. For Qt Creator 9.0.1 these private libraries are Qt 6.4.0. This set of private libraries is the one reported in the Qt Creator About box. These libraries have nothing to do with whatever version you built your program with.Your program may be built with any (some, or all) of the Qt library sets you see directly under
C:\Qt
(or any other Qt library set configured into a Kit with Qt Creator) and selected for your project. From what you said above, your program is probably built with Qt 6.3.2. -
so, I have a qstring varible which is created by added unsigned char values one by one. How can I solve this?
QString text; unsigned char char_to_add[10]; for(int i=0; i<9; i++) { text += char_to_add[i]; }
I do similar process in my code with several times. Problem comes in the inside of for loop line in this example.
-
Your code invokes QString::operator+=(QChar). It does this because your
unsigned char
can be used to construct a QChar to satisfy the QString operator. There are several QChar constructors that the compiler could use to do this and no way to select one for you, so your compiler gives you this error. In the case of GCC, the compiler output includes all the possibilities it considered.../untitled/main.cpp: In function ‘int main(int, char**)’: ../untitled/main.cpp:15:30: error: conversion from ‘unsigned char’ to ‘QChar’ is ambiguous 15 | text += char_to_add[i]; | ~~~~~~~~~~~~~^ In file included from /home/chrisw/Qt/6.4.0/gcc_64/include/QtCore/qstring.h:14, from /home/chrisw/Qt/6.4.0/gcc_64/include/QtCore/qobject.h:11, from /home/chrisw/Qt/6.4.0/gcc_64/include/QtWidgets/qwidget.h:9, from /home/chrisw/Qt/6.4.0/gcc_64/include/QtWidgets/qmainwindow.h:8, from /home/chrisw/Qt/6.4.0/gcc_64/include/QtWidgets/QMainWindow:1, from ../untitled/mainwindow.h:4, from ../untitled/main.cpp:1: /home/chrisw/Qt/6.4.0/gcc_64/include/QtCore/qchar.h:90:45: note: candidate: ‘constexpr QChar::QChar(char)’ 90 | QT_ASCII_CAST_WARN constexpr Q_IMPLICIT QChar(char c) noexcept : ucs(uchar(c)) { } | ^~~~~ /home/chrisw/Qt/6.4.0/gcc_64/include/QtCore/qchar.h:83:26: note: candidate: ‘constexpr QChar::QChar(char16_t)’ 83 | constexpr Q_IMPLICIT QChar(char16_t ch) noexcept : ucs(ch) {} | ^~~~~ /home/chrisw/Qt/6.4.0/gcc_64/include/QtCore/qchar.h:78:26: note: candidate: ‘constexpr QChar::QChar(short int)’ 78 | constexpr Q_IMPLICIT QChar(short rc) noexcept : ucs(char16_t(rc)) {} | ^~~~~ /home/chrisw/Qt/6.4.0/gcc_64/include/QtCore/qchar.h:76:26: note: candidate: ‘constexpr QChar::QChar(ushort)’ 76 | constexpr Q_IMPLICIT QChar(ushort rc) noexcept : ucs(rc) {} | ^~~~~ In file included from /home/chrisw/Qt/6.4.0/gcc_64/include/QtCore/qobject.h:11, from /home/chrisw/Qt/6.4.0/gcc_64/include/QtWidgets/qwidget.h:9, from /home/chrisw/Qt/6.4.0/gcc_64/include/QtWidgets/qmainwindow.h:8, from /home/chrisw/Qt/6.4.0/gcc_64/include/QtWidgets/QMainWindow:1, from ../untitled/mainwindow.h:4, from ../untitled/main.cpp:1: /home/chrisw/Qt/6.4.0/gcc_64/include/QtCore/qstring.h:697:38: note: initializing argument 1 of ‘QString& QString::operator+=(QChar)’ 697 | inline QString &operator+=(QChar c) { return append(c); } | ~~~~~~^
Choose the constructor explicitly (this assumes ASCII/Latin 1 char set):
text += QChar(char_to_add[i]);
-
Your code invokes QString::operator+=(QChar). It does this because your
unsigned char
can be used to construct a QChar to satisfy the QString operator. There are several QChar constructors that the compiler could use to do this and no way to select one for you, so your compiler gives you this error. In the case of GCC, the compiler output includes all the possibilities it considered.../untitled/main.cpp: In function ‘int main(int, char**)’: ../untitled/main.cpp:15:30: error: conversion from ‘unsigned char’ to ‘QChar’ is ambiguous 15 | text += char_to_add[i]; | ~~~~~~~~~~~~~^ In file included from /home/chrisw/Qt/6.4.0/gcc_64/include/QtCore/qstring.h:14, from /home/chrisw/Qt/6.4.0/gcc_64/include/QtCore/qobject.h:11, from /home/chrisw/Qt/6.4.0/gcc_64/include/QtWidgets/qwidget.h:9, from /home/chrisw/Qt/6.4.0/gcc_64/include/QtWidgets/qmainwindow.h:8, from /home/chrisw/Qt/6.4.0/gcc_64/include/QtWidgets/QMainWindow:1, from ../untitled/mainwindow.h:4, from ../untitled/main.cpp:1: /home/chrisw/Qt/6.4.0/gcc_64/include/QtCore/qchar.h:90:45: note: candidate: ‘constexpr QChar::QChar(char)’ 90 | QT_ASCII_CAST_WARN constexpr Q_IMPLICIT QChar(char c) noexcept : ucs(uchar(c)) { } | ^~~~~ /home/chrisw/Qt/6.4.0/gcc_64/include/QtCore/qchar.h:83:26: note: candidate: ‘constexpr QChar::QChar(char16_t)’ 83 | constexpr Q_IMPLICIT QChar(char16_t ch) noexcept : ucs(ch) {} | ^~~~~ /home/chrisw/Qt/6.4.0/gcc_64/include/QtCore/qchar.h:78:26: note: candidate: ‘constexpr QChar::QChar(short int)’ 78 | constexpr Q_IMPLICIT QChar(short rc) noexcept : ucs(char16_t(rc)) {} | ^~~~~ /home/chrisw/Qt/6.4.0/gcc_64/include/QtCore/qchar.h:76:26: note: candidate: ‘constexpr QChar::QChar(ushort)’ 76 | constexpr Q_IMPLICIT QChar(ushort rc) noexcept : ucs(rc) {} | ^~~~~ In file included from /home/chrisw/Qt/6.4.0/gcc_64/include/QtCore/qobject.h:11, from /home/chrisw/Qt/6.4.0/gcc_64/include/QtWidgets/qwidget.h:9, from /home/chrisw/Qt/6.4.0/gcc_64/include/QtWidgets/qmainwindow.h:8, from /home/chrisw/Qt/6.4.0/gcc_64/include/QtWidgets/QMainWindow:1, from ../untitled/mainwindow.h:4, from ../untitled/main.cpp:1: /home/chrisw/Qt/6.4.0/gcc_64/include/QtCore/qstring.h:697:38: note: initializing argument 1 of ‘QString& QString::operator+=(QChar)’ 697 | inline QString &operator+=(QChar c) { return append(c); } | ~~~~~~^
Choose the constructor explicitly (this assumes ASCII/Latin 1 char set):
text += QChar(char_to_add[i]);
-
@ChrisW67 thanks for the reply. I am not "extremely" know about Qt. How can I do last line of your reply?
@hubeytqew The ambiguity problem is a C++ language one, not Qt.
Modify the line of your code that reads:
text += char_to_add[i];
to read
text += QChar(char_to_add[i]);
-
@hubeytqew The ambiguity problem is a C++ language one, not Qt.
Modify the line of your code that reads:
text += char_to_add[i];
to read
text += QChar(char_to_add[i]);