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. convert accented characters from unicode at UTF-8
Forum Updated to NodeBB v4.3 + New Features

convert accented characters from unicode at UTF-8

Scheduled Pinned Locked Moved Solved General and Desktop
18 Posts 6 Posters 3.2k Views 3 Watching
  • 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.
  • elicatE Offline
    elicatE Offline
    elicat
    wrote on last edited by
    #1

    Hello,
    I need read from db access and write text UTF-8.

    I have this code for present string into html/webengine after read data .

    QString resultString = TextToHTML(strValue);
    

    But result si always this.

    ForumQtChar.JPG
    Where am I wrong?
    Of course, I also accept advice not to use an old-fashioned function.
    I tried to figure out QTextCodec but couldn't apply it for my purpose.

    In the Access db I see exactly like this
    ForumQtChar2.JPG

    Thanks for your answer.

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      What exactly is your problem? And please don't post screenshots but code.

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

      elicatE 1 Reply Last reply
      0
      • elicatE Offline
        elicatE Offline
        elicat
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          What exactly is your problem? And please don't post screenshots but code.

          elicatE Offline
          elicatE Offline
          elicat
          wrote on last edited by
          #4

          @Christian-Ehrlicher My problem
          I have this char "à" and it is view so :

          �
          
          KroMignonK 1 Reply Last reply
          0
          • elicatE elicat

            @Christian-Ehrlicher My problem
            I have this char "à" and it is view so :

            �
            
            KroMignonK Offline
            KroMignonK Offline
            KroMignon
            wrote on last edited by
            #5

            @elicat said in convert accented characters from unicode at UTF-8:

            My problem
            I have this char "à" and it is view so :
            �

            Are you sure you are reading the string correctly from DB?
            And why you do not use QString::toHtmlEscaped() to convert your UTF8 string into HTML escape sequence?

            It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

            elicatE 1 Reply Last reply
            2
            • KroMignonK KroMignon

              @elicat said in convert accented characters from unicode at UTF-8:

              My problem
              I have this char "à" and it is view so :
              �

              Are you sure you are reading the string correctly from DB?
              And why you do not use QString::toHtmlEscaped() to convert your UTF8 string into HTML escape sequence?

              elicatE Offline
              elicatE Offline
              elicat
              wrote on last edited by
              #6

              @KroMignon I have try

              QString::toHtmlEscaped()
              

              But not have difference "à" stay "à" and in html I see

              �
              
              KroMignonK 1 Reply Last reply
              0
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Apart from @KroMignon comment about to/fromHtmlEscaped() you have to make sure that your compiler treats your source as utf-8. MSVC is a little bit stupid with this so try to create your non-latin characters with a unicode sequence (e.g. \ue8 for è) or from a QChar.

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

                1 Reply Last reply
                2
                • elicatE elicat

                  @KroMignon I have try

                  QString::toHtmlEscaped()
                  

                  But not have difference "à" stay "à" and in html I see

                  �
                  
                  KroMignonK Offline
                  KroMignonK Offline
                  KroMignon
                  wrote on last edited by
                  #8

                  @elicat said in convert accented characters from unicode at UTF-8:

                  I have try
                  QString::toHtmlEscaped()

                  But not have difference "à" stay "à" and in html I see
                  �

                  I don't really understand your issue.
                  Do you want to generate an HTML page?
                  Why not simply force html page to UTF-8, so the web browser could read it.
                  Simply add <meta charset="utf-8"/> in the HEAD section.

                  It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                  elicatE 1 Reply Last reply
                  1
                  • S Offline
                    S Offline
                    SimonSchroeder
                    wrote on last edited by
                    #9

                    Since you are using accents in source code and expect them to be UTF-8, you should make sure that they are actually UTF-8.

                    1. Make sure your source code file is actually saved as UTF-8. In Qt Creator go to 'Edit' -> 'Select Encoding'. In the dialog the current encoding is highlighted. If it is not already UTF-8, select UTF-8 and choose 'Save with encoding'.
                    2. Make sure everything is compiled as UTF-8. This almost exclusively applies to Windows/MSVC. Microsoft's compiler has two places IIRC to set UTF-8: once for the source code and once for the compiled code.

                    You can try to print a character on standard output as well. On Windows (and only on Windows, so put a #ifdef around it) we use setlocale(LC_ALL, ".UTF8"); at the beginning of main to have input/output as UTF-8 as well.

                    1 Reply Last reply
                    1
                    • KroMignonK KroMignon

                      @elicat said in convert accented characters from unicode at UTF-8:

                      I have try
                      QString::toHtmlEscaped()

                      But not have difference "à" stay "à" and in html I see
                      �

                      I don't really understand your issue.
                      Do you want to generate an HTML page?
                      Why not simply force html page to UTF-8, so the web browser could read it.
                      Simply add <meta charset="utf-8"/> in the HEAD section.

                      elicatE Offline
                      elicatE Offline
                      elicat
                      wrote on last edited by
                      #10

                      @KroMignon hello, my project is QT/QML/QtWebengine with Db Access.
                      IN my Html head I have already

                      <meta charset="utf-8"/>
                      

                      This is a problem. I read "à" from Database but into html is present �

                      KroMignonK 1 Reply Last reply
                      0
                      • elicatE elicat

                        @KroMignon hello, my project is QT/QML/QtWebengine with Db Access.
                        IN my Html head I have already

                        <meta charset="utf-8"/>
                        

                        This is a problem. I read "à" from Database but into html is present �

                        KroMignonK Offline
                        KroMignonK Offline
                        KroMignon
                        wrote on last edited by KroMignon
                        #11

                        @elicat said in convert accented characters from unicode at UTF-8:

                        This is a problem. I read "à" from Database but into html is present �

                        You read à from DB, but with which code page?
                        Are you sure, it is UTF-8 and not Windows-1252 for example?

                        [EDIT]
                        Can you show how you read this string from DB?

                        It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                        elicatE 1 Reply Last reply
                        0
                        • KroMignonK KroMignon

                          @elicat said in convert accented characters from unicode at UTF-8:

                          This is a problem. I read "à" from Database but into html is present �

                          You read à from DB, but with which code page?
                          Are you sure, it is UTF-8 and not Windows-1252 for example?

                          [EDIT]
                          Can you show how you read this string from DB?

                          elicatE Offline
                          elicatE Offline
                          elicat
                          wrote on last edited by
                          #12

                          @KroMignon said in convert accented characters from unicode at UTF-8:

                          Windows-1252

                          No, the text in DB "à" when write into html is �.
                          if I saved "à" in the HTML with the meta charset set to UFT-8 it would be correct

                          KroMignonK D 2 Replies Last reply
                          0
                          • elicatE elicat

                            @KroMignon said in convert accented characters from unicode at UTF-8:

                            Windows-1252

                            No, the text in DB "à" when write into html is �.
                            if I saved "à" in the HTML with the meta charset set to UFT-8 it would be correct

                            KroMignonK Offline
                            KroMignonK Offline
                            KroMignon
                            wrote on last edited by
                            #13

                            @elicat said in convert accented characters from unicode at UTF-8:

                            No, the text in DB "à" when write into html is �.
                            if I saved "à" in the HTML with the meta charset set to UFT-8 it would be correct

                            Obviously your are doing something wrong somewhere.
                            There are not so many possibilities:

                            • the string is not read correctly from DB
                            • the string is not written correctly to output file. How do you write the string into to file?

                            I create a HTML export some days ago, which use UTF-8 chartset and it works fine.
                            Without showing how you have done it, it is not possible to help you more.

                            It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                            elicatE 1 Reply Last reply
                            0
                            • elicatE elicat

                              @KroMignon said in convert accented characters from unicode at UTF-8:

                              Windows-1252

                              No, the text in DB "à" when write into html is �.
                              if I saved "à" in the HTML with the meta charset set to UFT-8 it would be correct

                              D Offline
                              D Offline
                              deleted385
                              wrote on last edited by deleted385
                              #14

                              @elicat, no idea what your problem is BUT I saw this question mark in rotated rectangle in visual studio text editor for some Arabic diacritical marks (similar to yours) and asked about it in Microsoft's QA forum and they told it's because the keyboard layout I'm using uses 8 bit charset.

                              Is UTF-8 equivalent to 8 bit charset? If so, change that and see whether it solves the issue.

                              1 Reply Last reply
                              0
                              • KroMignonK KroMignon

                                @elicat said in convert accented characters from unicode at UTF-8:

                                No, the text in DB "à" when write into html is �.
                                if I saved "à" in the HTML with the meta charset set to UFT-8 it would be correct

                                Obviously your are doing something wrong somewhere.
                                There are not so many possibilities:

                                • the string is not read correctly from DB
                                • the string is not written correctly to output file. How do you write the string into to file?

                                I create a HTML export some days ago, which use UTF-8 chartset and it works fine.
                                Without showing how you have done it, it is not possible to help you more.

                                elicatE Offline
                                elicatE Offline
                                elicat
                                wrote on last edited by
                                #15

                                @KroMignon said in convert accented characters from unicode at UTF-8:

                                ring is not written correctly to output file. How do you write the string into to file?

                                I read from file db Acces width class QSqlQuery, for example :

                                QSqlQuery qSqlQueryObject;
                                QString valueField = qSqlQueryObject.value(fieldname).toString();
                                

                                After I write file HTML.
                                So i vae found "error". Was Missing set codec :

                                QTextStream pageStream(&file);
                                pageStream.setCodec("UTF-8");
                                
                                elicatE 1 Reply Last reply
                                0
                                • elicatE elicat

                                  @KroMignon said in convert accented characters from unicode at UTF-8:

                                  ring is not written correctly to output file. How do you write the string into to file?

                                  I read from file db Acces width class QSqlQuery, for example :

                                  QSqlQuery qSqlQueryObject;
                                  QString valueField = qSqlQueryObject.value(fieldname).toString();
                                  

                                  After I write file HTML.
                                  So i vae found "error". Was Missing set codec :

                                  QTextStream pageStream(&file);
                                  pageStream.setCodec("UTF-8");
                                  
                                  elicatE Offline
                                  elicatE Offline
                                  elicat
                                  wrote on last edited by
                                  #16

                                  @elicat
                                  I SOLVED !!!! Thank you all.

                                  I read weel but when I save text into file HTML I didn't set the codec

                                  QTextStream pageStream(&file);
                                  pageStream.setCodec("UTF-8");
                                  
                                  
                                  Pablo J. RoginaP elicatE 2 Replies Last reply
                                  1
                                  • elicatE elicat

                                    @elicat
                                    I SOLVED !!!! Thank you all.

                                    I read weel but when I save text into file HTML I didn't set the codec

                                    QTextStream pageStream(&file);
                                    pageStream.setCodec("UTF-8");
                                    
                                    
                                    Pablo J. RoginaP Offline
                                    Pablo J. RoginaP Offline
                                    Pablo J. Rogina
                                    wrote on last edited by
                                    #17

                                    @elicat said in convert accented characters from unicode at UTF-8:

                                    SOLVED

                                    Great! so please don't forget to mark your post as solved then.

                                    Upvote the answer(s) that helped you solve the issue
                                    Use "Topic Tools" button to mark your post as Solved
                                    Add screenshots via postimage.org
                                    Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                                    1 Reply Last reply
                                    0
                                    • elicatE elicat

                                      @elicat
                                      I SOLVED !!!! Thank you all.

                                      I read weel but when I save text into file HTML I didn't set the codec

                                      QTextStream pageStream(&file);
                                      pageStream.setCodec("UTF-8");
                                      
                                      
                                      elicatE Offline
                                      elicatE Offline
                                      elicat
                                      wrote on last edited by
                                      #18

                                      @elicat yes, I did

                                      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