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

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.
  • 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 �

        Saluti, Gianfranco Elicat

        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

            Saluti, Gianfranco Elicat

            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");
                  

                  Saluti, Gianfranco Elicat

                  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");
                    
                    

                    Saluti, Gianfranco Elicat

                    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

                        Saluti, Gianfranco Elicat

                        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