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
QtWS25 Last Chance

convert accented characters from unicode at UTF-8

Scheduled Pinned Locked Moved Solved General and Desktop
18 Posts 6 Posters 3.0k 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.
  • E Offline
    E Offline
    elicat
    wrote on 16 Nov 2021, 16:00 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
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 16 Nov 2021, 16:03 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

      E 1 Reply Last reply 16 Nov 2021, 16:51
      0
      • E Offline
        E Offline
        elicat
        wrote on 16 Nov 2021, 16:51 last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • C Christian Ehrlicher
          16 Nov 2021, 16:03

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

          E Offline
          E Offline
          elicat
          wrote on 16 Nov 2021, 16:51 last edited by
          #4

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

          �
          
          K 1 Reply Last reply 16 Nov 2021, 16:54
          0
          • E elicat
            16 Nov 2021, 16:51

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

            �
            
            K Offline
            K Offline
            KroMignon
            wrote on 16 Nov 2021, 16:54 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)

            E 1 Reply Last reply 16 Nov 2021, 17:54
            2
            • K KroMignon
              16 Nov 2021, 16:54

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

              E Offline
              E Offline
              elicat
              wrote on 16 Nov 2021, 17:54 last edited by
              #6

              @KroMignon I have try

              QString::toHtmlEscaped()
              

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

              �
              
              K 1 Reply Last reply 16 Nov 2021, 19:26
              0
              • C Offline
                C Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on 16 Nov 2021, 17:57 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
                • E elicat
                  16 Nov 2021, 17:54

                  @KroMignon I have try

                  QString::toHtmlEscaped()
                  

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

                  �
                  
                  K Offline
                  K Offline
                  KroMignon
                  wrote on 16 Nov 2021, 19:26 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)

                  E 1 Reply Last reply 17 Nov 2021, 09:04
                  1
                  • S Offline
                    S Offline
                    SimonSchroeder
                    wrote on 17 Nov 2021, 08:11 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
                    • K KroMignon
                      16 Nov 2021, 19:26

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

                      E Offline
                      E Offline
                      elicat
                      wrote on 17 Nov 2021, 09:04 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 �

                      K 1 Reply Last reply 17 Nov 2021, 09:07
                      0
                      • E elicat
                        17 Nov 2021, 09:04

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

                        K Offline
                        K Offline
                        KroMignon
                        wrote on 17 Nov 2021, 09:07 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)

                        E 1 Reply Last reply 17 Nov 2021, 09:37
                        0
                        • K KroMignon
                          17 Nov 2021, 09:07

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

                          E Offline
                          E Offline
                          elicat
                          wrote on 17 Nov 2021, 09:37 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

                          K D 2 Replies Last reply 17 Nov 2021, 09:44
                          0
                          • E elicat
                            17 Nov 2021, 09:37

                            @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

                            K Offline
                            K Offline
                            KroMignon
                            wrote on 17 Nov 2021, 09:44 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)

                            E 1 Reply Last reply 17 Nov 2021, 11:21
                            0
                            • E elicat
                              17 Nov 2021, 09:37

                              @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 17 Nov 2021, 09:56 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
                              • K KroMignon
                                17 Nov 2021, 09:44

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

                                E Offline
                                E Offline
                                elicat
                                wrote on 17 Nov 2021, 11:21 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");
                                
                                E 1 Reply Last reply 17 Nov 2021, 11:24
                                0
                                • E elicat
                                  17 Nov 2021, 11:21

                                  @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");
                                  
                                  E Offline
                                  E Offline
                                  elicat
                                  wrote on 17 Nov 2021, 11:24 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 E 2 Replies Last reply 17 Nov 2021, 11:25
                                  1
                                  • E elicat
                                    17 Nov 2021, 11:24

                                    @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 17 Nov 2021, 11:25 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
                                    • E elicat
                                      17 Nov 2021, 11:24

                                      @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");
                                      
                                      
                                      E Offline
                                      E Offline
                                      elicat
                                      wrote on 17 Nov 2021, 11:26 last edited by
                                      #18

                                      @elicat yes, I did

                                      1 Reply Last reply
                                      0

                                      7/18

                                      16 Nov 2021, 17:57

                                      • Login

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