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. Add special characters as text to QTextEditor or other widgets
Forum Updated to NodeBB v4.3 + New Features

Add special characters as text to QTextEditor or other widgets

Scheduled Pinned Locked Moved Unsolved General and Desktop
15 Posts 3 Posters 977 Views 2 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.
  • Q Offline
    Q Offline
    Q139
    wrote on last edited by
    #1

    How to add special characters as text to QTextEditor or other widgets?

    For example "l1 /n l2" not to create new line but to display it on single line with special character of newline...

    Pl45m4P 1 Reply Last reply
    0
    • Q Q139

      How to add special characters as text to QTextEditor or other widgets?

      For example "l1 /n l2" not to create new line but to display it on single line with special character of newline...

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #2

      @Q139 said in Add special characters as text to QTextEditor or other widgets:

      "l1 /n l2"

      Maybe because it's \n :)

      Edit:

      Misread your comment.
      You need to escape the \n in order to display the \ as backslash


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      Q 1 Reply Last reply
      0
      • Pl45m4P Pl45m4

        @Q139 said in Add special characters as text to QTextEditor or other widgets:

        "l1 /n l2"

        Maybe because it's \n :)

        Edit:

        Misread your comment.
        You need to escape the \n in order to display the \ as backslash

        Q Offline
        Q Offline
        Q139
        wrote on last edited by Q139
        #3

        @Pl45m4 If i add another "\" as "l1 \\n l2" then i get "l1 \n l2" to QTextBrowser , but i am unable to write a search function to auto replace every "\" with "\\"

        jsulmJ Pl45m4P 2 Replies Last reply
        0
        • Q Q139

          @Pl45m4 If i add another "\" as "l1 \\n l2" then i get "l1 \n l2" to QTextBrowser , but i am unable to write a search function to auto replace every "\" with "\\"

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Q139 said in Add special characters as text to QTextEditor or other widgets:

          but i am unable to write a search function to auto replace every "" with ""

          Why not? What did you try?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          Q 1 Reply Last reply
          1
          • Q Q139

            @Pl45m4 If i add another "\" as "l1 \\n l2" then i get "l1 \n l2" to QTextBrowser , but i am unable to write a search function to auto replace every "\" with "\\"

            Pl45m4P Offline
            Pl45m4P Offline
            Pl45m4
            wrote on last edited by
            #5

            @Q139

            If you have a string, you can simply replace \ with \\


            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            Q 1 Reply Last reply
            0
            • jsulmJ jsulm

              @Q139 said in Add special characters as text to QTextEditor or other widgets:

              but i am unable to write a search function to auto replace every "" with ""

              Why not? What did you try?

              Q Offline
              Q Offline
              Q139
              wrote on last edited by Q139
              #6

              @jsulm

              text.indexOf('\'); //wont compile
              text.indexOf('\\'); //wont find the text as special chars are threated as single char..
              
              
              jsulmJ 1 Reply Last reply
              0
              • Pl45m4P Pl45m4

                @Q139

                If you have a string, you can simply replace \ with \\

                Q Offline
                Q Offline
                Q139
                wrote on last edited by Q139
                #7

                @Pl45m4 how to replace it without seeking for each special char seperately?
                After compiled to string it is threated as single special char...
                Basically id like to show all info as raw text in text browser. Including \n \r etc but incoming data format is QString...

                1 Reply Last reply
                0
                • Q Q139

                  @jsulm

                  text.indexOf('\'); //wont compile
                  text.indexOf('\\'); //wont find the text as special chars are threated as single char..
                  
                  
                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by jsulm
                  #8

                  @Q139 said in Add special characters as text to QTextEditor or other widgets:

                  text.indexOf('\'); //wont compile

                  Of course not.

                  Regarding text.indexOf('\'); : you want to replace new-lines, right? So, it should be:

                  text.indexOf('\n');
                  

                  To replace a simple

                  someString.replace("\n", "\\n");
                  

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  Q 1 Reply Last reply
                  0
                  • jsulmJ jsulm

                    @Q139 said in Add special characters as text to QTextEditor or other widgets:

                    text.indexOf('\'); //wont compile

                    Of course not.

                    Regarding text.indexOf('\'); : you want to replace new-lines, right? So, it should be:

                    text.indexOf('\n');
                    

                    To replace a simple

                    someString.replace("\n", "\\n");
                    
                    Q Offline
                    Q Offline
                    Q139
                    wrote on last edited by Q139
                    #9

                    @jsulm Not only new lines but all special chars..

                    I guess 1 way is to loop trough text and use isNonCharacter() then add the extra "\"

                    Pl45m4P 1 Reply Last reply
                    0
                    • Q Q139

                      @jsulm Not only new lines but all special chars..

                      I guess 1 way is to loop trough text and use isNonCharacter() then add the extra "\"

                      Pl45m4P Offline
                      Pl45m4P Offline
                      Pl45m4
                      wrote on last edited by
                      #10

                      @Q139

                      If you want to replace \ with \\
                      text.replace ("\\", "\\\" );


                      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                      ~E. W. Dijkstra

                      Q 1 Reply Last reply
                      0
                      • Pl45m4P Pl45m4

                        @Q139

                        If you want to replace \ with \\
                        text.replace ("\\", "\\\" );

                        Q Offline
                        Q Offline
                        Q139
                        wrote on last edited by
                        #11

                        @Pl45m4 Nice try

                        jsulmJ Q 2 Replies Last reply
                        0
                        • Q Q139

                          @Pl45m4 Nice try

                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          @Q139 One idea would be to take a look at qDebug() implementation as it does this at least for some special characters (like new lines).

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          0
                          • Q Q139

                            @Pl45m4 Nice try

                            Q Offline
                            Q Offline
                            Q139
                            wrote on last edited by
                            #13

                            @Q139 im afraid compiler removes 2 chars and replaces with 1 as there are not enough keys on keyboard for special chars.

                            Pl45m4P 1 Reply Last reply
                            0
                            • Q Q139

                              @Q139 im afraid compiler removes 2 chars and replaces with 1 as there are not enough keys on keyboard for special chars.

                              Pl45m4P Offline
                              Pl45m4P Offline
                              Pl45m4
                              wrote on last edited by
                              #14

                              @Q139

                              Check: https://forum.qt.io/topic/94161/replace-the-character-with-in-the-qstring


                              If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                              ~E. W. Dijkstra

                              Q 1 Reply Last reply
                              0
                              • Pl45m4P Pl45m4

                                @Q139

                                Check: https://forum.qt.io/topic/94161/replace-the-character-with-in-the-qstring

                                Q Offline
                                Q Offline
                                Q139
                                wrote on last edited by
                                #15

                                @Pl45m4

                                I have incoming data in QString format...

                                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