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. [SOLVED] remove html from the textEdit widget?
QtWS25 Last Chance

[SOLVED] remove html from the textEdit widget?

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 4.6k 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.
  • K Offline
    K Offline
    kalster
    wrote on last edited by
    #1

    when i send a blank message from server to client textEdit, i get the following message displayed. i have tried removing that extra line brakes without any luck. I have tried QRegExp, <br> <p> but they do not works. how to remove this extra garbage from the textEdit widget and without using toPlainText?

    here is the garbage ---------------------------
    User:
    User:
    User: p, li { white-space: pre-wrap; }
    User:

    User:

    the client sends to the server the message in UTf8 and returns it the same way. when i get the message back, i get the garbage above. when the server gets the message, a bunch of html entities are displayed.

    @QString message = ui->sayLineEdit->toHtml().trimmed();
    socket->write(QString(message + "\n").toUtf8());@

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kalster
      wrote on last edited by
      #2

      i really need some help in this matter. anyone have any advice?

      1 Reply Last reply
      0
      • L Offline
        L Offline
        LinusA
        wrote on last edited by
        #3

        [quote author="kalster" date="1313883400"]i have tried removing that extra line brakes without any luck. I have tried QRegExp, <br> <p> but they do not works.
        [/quote]
        What did you try? Post code. What did not work? Post results and/or error messages.

        [quote author="kalster" date="1313883400"]
        how to remove this extra garbage from the textEdit widget and without using toPlainText?
        [/quote]
        Actually, .toPlainText() sounds very much like what you need. Why not use it? Can't you make a hidden copy of the text edit and use .toPlainText() there, if nothing else helps?

        [quote author="kalster" date="1313883400"]
        the client sends to the server the message in UTf8 and returns it the same way. when i get the message back, i get the garbage above. when the server gets the message, a bunch of html entities are displayed.
        [/quote]
        You are in control of the messages, it seems. Why do you send the garbage in the first please? You could just not send it? It looks you specifically send it as HTML, which might not make sense. Can't you just do
        @
        QString message = ui->sayLineEdit->toPlainText().trimmed();
        @
        ?

        [quote author="kalster" date="1313883400"]
        p, li { white-space: pre-wrap; }
        [/quote]
        If this is your garbage, you can use
        @
        message.replace("p, li { white-space: pre-wrap; }", "");
        @
        to remove it.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kalster
          wrote on last edited by
          #4

          i have a client and server. i am using textedit because i want html in the code. when the client sends the formatted code to the server, the server displays all the html in the message including the <html> and <body>, styles, ect, as in the code below.

          @QString message = ui->sayLineEdit->toHtml().trimmed();
          socket->write(QString(message + "\n").toUtf8());@

          if i do toPlainText then the user has no bold in the text. I need html in there but not the extra html that i get after the message is sent to the server..

          QString message = ui->sayLineEdit->toPlainText().trimmed();

          the server reads the message from the client and the code is here...
          @ QString line = QString::fromUtf8(client->readLine()).trimmed();@

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kalster
            wrote on last edited by
            #5

            does anyone have another method to read and write to the server. the method i am using create garbage in the message.

            I am trying the use mid to remove the garbage at the beginning of the client output message but its not working. all of the message length is displayed, yet i have mid set to 40. below is the code.

            @@QString message = ui->sayLineEdit->toHtml().trimmed();
            

            message == message.mid(40,-1);@

            1 Reply Last reply
            0
            • L Offline
              L Offline
              LinusA
              wrote on last edited by
              #6

              Ok, post an example please. Post an exact copy of a message that you send, and the version that you receive (use @ tags for formatting please). Maybe this illustrates the problem.

              1 Reply Last reply
              0
              • K Offline
                K Offline
                kalster
                wrote on last edited by
                #7

                i have decided to take your advice and go with the toPlainText(). what way i do not get any html display problems

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  Python
                  wrote on last edited by
                  #8

                  This is my junk:
                  {\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf360 {\fonttbl\f0\fswiss\fcharset0 Helvetica;} {\colortbl;\red255\green255\blue255;} \vieww9000\viewh8400\viewkind0 \deftab720 \pard\pardeftab720\ql\qnatural \f0\fs24 \cf0 \
                  Hi!

                  \ \ \ }

                  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