Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. 'unsigned char' to 'QChar' is ambiguous..but different
Forum Updated to NodeBB v4.3 + New Features

'unsigned char' to 'QChar' is ambiguous..but different

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 2.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hubeytqew
    wrote on last edited by
    #1

    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

    Christian EhrlicherC C 2 Replies Last reply
    0
    • H hubeytqew

      @ChrisW67 thanks for the reply. I am not "extremely" know about Qt. How can I do last line of your reply?

      C Offline
      C Offline
      ChrisW67
      wrote on last edited by ChrisW67
      #8

      @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]);
      
      H 1 Reply Last reply
      1
      • H hubeytqew

        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

        Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @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.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        H 1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          @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.

          H Offline
          H Offline
          hubeytqew
          wrote on last edited by hubeytqew
          #3

          @Christian-Ehrlicher oh the problem its normal..Thanks..

          1 Reply Last reply
          0
          • H hubeytqew

            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

            C Offline
            C Offline
            ChrisW67
            wrote on last edited by
            #4

            @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.

            1 Reply Last reply
            1
            • H Offline
              H Offline
              hubeytqew
              wrote on last edited by
              #5

              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.

              1 Reply Last reply
              0
              • C Offline
                C Offline
                ChrisW67
                wrote on last edited by ChrisW67
                #6

                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]);
                
                H 1 Reply Last reply
                1
                • C ChrisW67

                  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]);
                  
                  H Offline
                  H Offline
                  hubeytqew
                  wrote on last edited by
                  #7

                  @ChrisW67 thanks for the reply. I am not "extremely" know about Qt. How can I do last line of your reply?

                  C 1 Reply Last reply
                  0
                  • H hubeytqew

                    @ChrisW67 thanks for the reply. I am not "extremely" know about Qt. How can I do last line of your reply?

                    C Offline
                    C Offline
                    ChrisW67
                    wrote on last edited by ChrisW67
                    #8

                    @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]);
                    
                    H 1 Reply Last reply
                    1
                    • C ChrisW67

                      @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]);
                      
                      H Offline
                      H Offline
                      hubeytqew
                      wrote on last edited by
                      #9

                      @ChrisW67 aah..I did not see the QChar addition in the your past answer..thanks, you solved my problem.

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved