[SOLVED] remove html from the textEdit widget?



  • 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());@



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



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



  • 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();@



  • 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);@



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



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



  • 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!

    \ \ \ }


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.