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. How can i convert Utf-8 encoding to normal text
Forum Updated to NodeBB v4.3 + New Features

How can i convert Utf-8 encoding to normal text

Scheduled Pinned Locked Moved Solved General and Desktop
qstringutf-8text
15 Posts 3 Posters 18.9k 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.
  • R raven-worx
    24 Aug 2016, 05:51

    @Rohith
    unfortunately i do not understand yet.
    Unicode should contain the Bengali characters no? So it should be displayed correctly?!
    Where do you dont get your desired output displayed? Is it only about the qDebug output?

    R Offline
    R Offline
    Rohith
    wrote on 24 Aug 2016, 06:25 last edited by
    #6

    @raven-worx

    Let me try one more time

    I am converting Bengali letters into** Utf-8 encoding** and i am storing the **converted Utf-8 encoding of Bengali letters in to a file **and, i want to read the data present in the file i.e i want to the Utf-8 encoded text from file and i want to convert encoding i.e Utf-8 encoded data into bengali letters and then i want to display the Bengali data that came from Utf-8 encoding that was present in file.

    R 1 Reply Last reply 24 Aug 2016, 06:31
    0
    • R Rohith
      24 Aug 2016, 06:25

      @raven-worx

      Let me try one more time

      I am converting Bengali letters into** Utf-8 encoding** and i am storing the **converted Utf-8 encoding of Bengali letters in to a file **and, i want to read the data present in the file i.e i want to the Utf-8 encoded text from file and i want to convert encoding i.e Utf-8 encoded data into bengali letters and then i want to display the Bengali data that came from Utf-8 encoding that was present in file.

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 24 Aug 2016, 06:31 last edited by
      #7

      @Rohith said:

      convert encoding i.e Utf-8 encoded data into bengali letters

      the question is what encoding do you expect for the "bengali letters"?!
      Since the bengali characters can already be stored using UTF-8 encoding!

      Still u didn't tell me where you have problems displaying it...

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      R 1 Reply Last reply 24 Aug 2016, 06:53
      0
      • R raven-worx
        24 Aug 2016, 06:31

        @Rohith said:

        convert encoding i.e Utf-8 encoded data into bengali letters

        the question is what encoding do you expect for the "bengali letters"?!
        Since the bengali characters can already be stored using UTF-8 encoding!

        Still u didn't tell me where you have problems displaying it...

        R Offline
        R Offline
        Rohith
        wrote on 24 Aug 2016, 06:53 last edited by
        #8

        @raven-worx
        Here I am trying to convert Bengali Unicode to Bengali text and print that.
        Bengali Unicode is present in file, and I am trying to read that Unicode from file and convert it to original Bengali text

        This is Original Bengali Text :- "সবাইকে শুভ সকাল"
        The unicode reading from file :- \u09b8\u09ac\u09be\u0987\u0995\u09c7 \u09b6\u09c1\u09ad \u09b8\u0995\u09be\u09b2

        O/P to be shown after reading unicode from file :- সবাইকে শুভ সকাল

        We are getting problem that whenever we are trying to read unicode from file dynamically and convert to original text.

        As we are passing unicode Text statically its working fine.

        R 1 Reply Last reply 24 Aug 2016, 07:00
        0
        • R Rohith
          24 Aug 2016, 06:53

          @raven-worx
          Here I am trying to convert Bengali Unicode to Bengali text and print that.
          Bengali Unicode is present in file, and I am trying to read that Unicode from file and convert it to original Bengali text

          This is Original Bengali Text :- "সবাইকে শুভ সকাল"
          The unicode reading from file :- \u09b8\u09ac\u09be\u0987\u0995\u09c7 \u09b6\u09c1\u09ad \u09b8\u0995\u09be\u09b2

          O/P to be shown after reading unicode from file :- সবাইকে শুভ সকাল

          We are getting problem that whenever we are trying to read unicode from file dynamically and convert to original text.

          As we are passing unicode Text statically its working fine.

          R Offline
          R Offline
          raven-worx
          Moderators
          wrote on 24 Aug 2016, 07:00 last edited by
          #9

          @Rohith said:

          The unicode reading from file :- \u09b8\u09ac\u09be\u0987\u0995\u09c7 \u09b6\u09c1\u09ad \u09b8\u0995\u09be\u09b2

          You mean this is the content of the file as text-representation?
          Can you please upload an example file?

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          R 1 Reply Last reply 24 Aug 2016, 07:07
          0
          • R raven-worx
            24 Aug 2016, 07:00

            @Rohith said:

            The unicode reading from file :- \u09b8\u09ac\u09be\u0987\u0995\u09c7 \u09b6\u09c1\u09ad \u09b8\u0995\u09be\u09b2

            You mean this is the content of the file as text-representation?
            Can you please upload an example file?

            R Offline
            R Offline
            Rohith
            wrote on 24 Aug 2016, 07:07 last edited by
            #10

            @raven-worx

            Yeah that is what i mean

            \u09b8\u09ac\u09be\u0987\u0995\u09c7 \u09b6\u09c1\u09ad \u09b8\u0995\u09be\u09b2

            save this content in to a .txt file and try to read the content form the file and present it as normal text

            here i am not getting how to upload file in this forum

            R 1 Reply Last reply 24 Aug 2016, 07:12
            0
            • R Rohith
              24 Aug 2016, 07:07

              @raven-worx

              Yeah that is what i mean

              \u09b8\u09ac\u09be\u0987\u0995\u09c7 \u09b6\u09c1\u09ad \u09b8\u0995\u09be\u09b2

              save this content in to a .txt file and try to read the content form the file and present it as normal text

              here i am not getting how to upload file in this forum

              R Offline
              R Offline
              raven-worx
              Moderators
              wrote on 24 Aug 2016, 07:12 last edited by raven-worx
              #11

              @Rohith
              finally we get together, since this is an important info.
              You then have to "parse" the text data to the desired unicode representation.

              QString str = ...; // read from the file
              int idx = -1;
              while ( ( idx = str.indexOf("\\u") ) != -1 )
              {
                    int uc = str.mid(idx+2, 4).toInt(0,16);
                    str.replace(idx, 6, QChar(uc));
              }
              

              The reason it worked "statically" for you was, that the compiler already did the correct interpretation for you during compilation.

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              R 1 Reply Last reply 24 Aug 2016, 09:11
              0
              • R raven-worx
                24 Aug 2016, 07:12

                @Rohith
                finally we get together, since this is an important info.
                You then have to "parse" the text data to the desired unicode representation.

                QString str = ...; // read from the file
                int idx = -1;
                while ( ( idx = str.indexOf("\\u") ) != -1 )
                {
                      int uc = str.mid(idx+2, 4).toInt(0,16);
                      str.replace(idx, 6, QChar(uc));
                }
                

                The reason it worked "statically" for you was, that the compiler already did the correct interpretation for you during compilation.

                R Offline
                R Offline
                Rohith
                wrote on 24 Aug 2016, 09:11 last edited by
                #12

                @raven-worx

                Thanks it worked....!

                R 1 Reply Last reply 24 Aug 2016, 09:17
                0
                • R Rohith
                  24 Aug 2016, 09:11

                  @raven-worx

                  Thanks it worked....!

                  R Offline
                  R Offline
                  raven-worx
                  Moderators
                  wrote on 24 Aug 2016, 09:17 last edited by raven-worx
                  #13

                  @Rohith
                  just to clarify:
                  To transfer this information this way is rather resource wasteful.
                  Since you create for 1 Unicode character 6 ASCII characters. This means (roughly - not exact) a factor of 6. Additionally you have to do the parsing.

                  If possible i would change it, so the unicode text is transfered as "RAW" unicode in binary format.

                  --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                  If you have a question please use the forum so others can benefit from the solution in the future

                  R 1 Reply Last reply 24 Aug 2016, 09:36
                  0
                  • R raven-worx
                    24 Aug 2016, 09:17

                    @Rohith
                    just to clarify:
                    To transfer this information this way is rather resource wasteful.
                    Since you create for 1 Unicode character 6 ASCII characters. This means (roughly - not exact) a factor of 6. Additionally you have to do the parsing.

                    If possible i would change it, so the unicode text is transfered as "RAW" unicode in binary format.

                    R Offline
                    R Offline
                    Rohith
                    wrote on 24 Aug 2016, 09:36 last edited by
                    #14

                    @raven-worx

                    If possible please provide me that too..!

                    Thanks,
                    Rohith.G

                    R 1 Reply Last reply 24 Aug 2016, 09:45
                    0
                    • R Rohith
                      24 Aug 2016, 09:36

                      @raven-worx

                      If possible please provide me that too..!

                      Thanks,
                      Rohith.G

                      R Offline
                      R Offline
                      raven-worx
                      Moderators
                      wrote on 24 Aug 2016, 09:45 last edited by
                      #15

                      @Rohith
                      instead of converting the unicode string to the escaped characters send it directly in binary form. When you have a QString already you can call QString::toUtf8() and send the returned QByteArray directly. On the client its enough to do QString::fromUtf8( receivedUtf8ByteArray.constData() )

                      It depends how you implemented the transfer.
                      But theoretically it should be enough to replace your unicode escaping code on the server with this approach.

                      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                      If you have a question please use the forum so others can benefit from the solution in the future

                      1 Reply Last reply
                      1

                      15/15

                      24 Aug 2016, 09:45

                      • Login

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