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. Extended Ascii Codes in QTextEdit
Forum Updated to NodeBB v4.3 + New Features

Extended Ascii Codes in QTextEdit

Scheduled Pinned Locked Moved Solved General and Desktop
22 Posts 3 Posters 11.1k Views 1 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.
  • M Offline
    M Offline
    mulfycrowh
    wrote on 24 Sept 2016, 19:58 last edited by
    #4

    Thank you. That's exactly what I meant !

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mulfycrowh
      wrote on 24 Sept 2016, 20:12 last edited by
      #5

      Is it the only way to achieve this ?

      1 Reply Last reply
      0
      • H Offline
        H Offline
        hskoglund
        wrote on 25 Sept 2016, 01:40 last edited by
        #6

        Hmm you mean you don't like QChar? If you only want to use QString stuff, you could rewrite it (output looks the same) to:

            QString s;
            for (ushort u = 0; (u < 2048); ++u)
                s += QString::fromUtf16(&u,1);
        
            ui->textEdit->setText(s);
        
        1 Reply Last reply
        1
        • M Offline
          M Offline
          mulfycrowh
          wrote on 25 Sept 2016, 08:57 last edited by
          #7

          I tried this:

          QString s;
          s = "test ";
          s += QChar(225);
          ui.Test->setText(s);
          

          It does display "test a", a with accent instead of "test ß".

          K 1 Reply Last reply 25 Sept 2016, 09:52
          0
          • M mulfycrowh
            25 Sept 2016, 08:57

            I tried this:

            QString s;
            s = "test ";
            s += QChar(225);
            ui.Test->setText(s);
            

            It does display "test a", a with accent instead of "test ß".

            K Offline
            K Offline
            kshegunov
            Moderators
            wrote on 25 Sept 2016, 09:52 last edited by
            #8

            Because the 225th char in the utf-16 table[1] is an á. QChar is a single character (2 bytes) in utf-16.
            [1]: http://asecuritysite.com/coding/asc2

            Read and abide by the Qt Code of Conduct

            M 1 Reply Last reply 25 Sept 2016, 10:06
            0
            • K kshegunov
              25 Sept 2016, 09:52

              Because the 225th char in the utf-16 table[1] is an á. QChar is a single character (2 bytes) in utf-16.
              [1]: http://asecuritysite.com/coding/asc2

              M Offline
              M Offline
              mulfycrowh
              wrote on 25 Sept 2016, 10:06 last edited by
              #9

              @kshegunov Thank you. So how can I manage it to get the character ß ?

              K 1 Reply Last reply 25 Sept 2016, 10:10
              0
              • M mulfycrowh
                25 Sept 2016, 10:06

                @kshegunov Thank you. So how can I manage it to get the character ß ?

                K Offline
                K Offline
                kshegunov
                Moderators
                wrote on 25 Sept 2016, 10:10 last edited by kshegunov
                #10

                You go to the wiki page and at the bottom you find what's the codepoint of said character in unicode. Then you google that and you get this nifty page. Finally you get the code for the character and insert in as an argument of QChar:

                s += QChar(223);
                

                Read and abide by the Qt Code of Conduct

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mulfycrowh
                  wrote on 25 Sept 2016, 10:58 last edited by
                  #11

                  I tried this:

                  		QString s;
                  		s = "test ";
                  		ushort u = 223;
                  		s += QString::fromUtf16(&u, 1);
                  		u = 147;
                  		s += QString::fromUtf16(&u, 1);
                  		ui.Test->setText(s);
                  

                  ß is displayed but not the second one (").
                  Does it show that extended characters' display in QTextEdit is not possible ?

                  K 1 Reply Last reply 25 Sept 2016, 11:30
                  0
                  • M mulfycrowh
                    25 Sept 2016, 10:58

                    I tried this:

                    		QString s;
                    		s = "test ";
                    		ushort u = 223;
                    		s += QString::fromUtf16(&u, 1);
                    		u = 147;
                    		s += QString::fromUtf16(&u, 1);
                    		ui.Test->setText(s);
                    

                    ß is displayed but not the second one (").
                    Does it show that extended characters' display in QTextEdit is not possible ?

                    K Offline
                    K Offline
                    kshegunov
                    Moderators
                    wrote on 25 Sept 2016, 11:30 last edited by
                    #12

                    @mulfycrowh said in Extended Ascii Codes in QTextEdit:

                    Does it show that extended characters' display in QTextEdit is not possible ?

                    Firstly, there's no "extended characters", there are different encodings for representing text and Qt uses utf-16. Secondly, showing text in QTextEdit is possible and if the font you're using has a glyph for the character you're trying to display, then the character will be displayed. And finally, have you checked what is corresponding to the number 147 in the first utf-16 table I've posted as a link? I see no corresponding character for that code, so what are you expecting to see exactly? Where do you get 147?

                    Read and abide by the Qt Code of Conduct

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      mulfycrowh
                      wrote on 25 Sept 2016, 12:14 last edited by kshegunov
                      #13

                      I found this table:

                      alt text

                      and you get the characters with the matching decimal code

                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        mulfycrowh
                        wrote on 25 Sept 2016, 12:14 last edited by
                        #14
                        This post is deleted!
                        1 Reply Last reply
                        0
                        • M Offline
                          M Offline
                          mulfycrowh
                          wrote on 25 Sept 2016, 12:18 last edited by
                          #15
                          This post is deleted!
                          1 Reply Last reply
                          0
                          • M Offline
                            M Offline
                            mulfycrowh
                            wrote on 25 Sept 2016, 13:48 last edited by
                            #16

                            Explanation: I have a file with hex bytes equal to 93, 94, 96 ... and I would like to display the matching characters into a QTextEdit.

                            1 Reply Last reply
                            0
                            • M Offline
                              M Offline
                              mulfycrowh
                              wrote on 25 Sept 2016, 14:52 last edited by
                              #17

                              I found the solution in adding fromLatin1()

                              1 Reply Last reply
                              0
                              • M Offline
                                M Offline
                                mulfycrowh
                                wrote on 25 Sept 2016, 15:45 last edited by
                                #18

                                With fromLatin1(), it's better: I have no more losange with ? but, for example hex codes 93 and 94 are not displayed.

                                1 Reply Last reply
                                0
                                • M Offline
                                  M Offline
                                  mulfycrowh
                                  wrote on 25 Sept 2016, 17:36 last edited by
                                  #19

                                  From Wikipedia, I copy and paste some text.
                                  In this text I have the character (Hex 92) (') and the character (Hex E9) (é).
                                  The second one is displayed. The first one is replaced by a chinese character.
                                  Why ?

                                  1 Reply Last reply
                                  0
                                  • M Offline
                                    M Offline
                                    mulfycrowh
                                    wrote on 25 Sept 2016, 17:57 last edited by
                                    #20

                                    I think having found the perfect solution :)

                                    I copied and pasted many articles from Wikipedia in French, English and German and it runs.
                                    The solution is to use:

                                    FromLocal8Bit()
                                    
                                    K 1 Reply Last reply 25 Sept 2016, 23:19
                                    1
                                    • M mulfycrowh
                                      25 Sept 2016, 17:57

                                      I think having found the perfect solution :)

                                      I copied and pasted many articles from Wikipedia in French, English and German and it runs.
                                      The solution is to use:

                                      FromLocal8Bit()
                                      
                                      K Offline
                                      K Offline
                                      kshegunov
                                      Moderators
                                      wrote on 25 Sept 2016, 23:19 last edited by
                                      #21

                                      As long as it works for you. I wouldn't depend on the local 8bit encoding myself, but that's just me.

                                      Read and abide by the Qt Code of Conduct

                                      M 1 Reply Last reply 26 Sept 2016, 07:57
                                      1
                                      • K kshegunov
                                        25 Sept 2016, 23:19

                                        As long as it works for you. I wouldn't depend on the local 8bit encoding myself, but that's just me.

                                        M Offline
                                        M Offline
                                        mulfycrowh
                                        wrote on 26 Sept 2016, 07:57 last edited by
                                        #22

                                        @kshegunov That's the only way to make it perfectly running. Do you have other idea in mind ?

                                        1 Reply Last reply
                                        0

                                        13/22

                                        25 Sept 2016, 12:14

                                        • Login

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