Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i convert entity character(Escape character) to HTML in QT?

Tags:

c++

qt

I want to convert entity character(Escape character) to HTML in QT, please help me....

i.e: I want to replace " with ", > with >

=====This is my code that not worked====

   QString MyApp::ReplaceString(const QString Data, const QString &Before, const      QString &After)
{

    QString Result = Data;
    Result.replace(Before, After, Qt::CaseInsensitive);
    return Result;
}

========

QTextCodec *codec = QTextCodec::codecForName("UTF-8");
QByteArray data=pReply->readAll();
QString str = codec->toUnicode((const char *)data);

str = Qt::escape(str);
str = ReplaceString(str, """, "\"");   

str = ReplaceString(str,">", ">");
like image 606
N K Avatar asked Oct 08 '11 10:10

N K


2 Answers

I'm not sure I understand what you want, just guessing. You can use QTextDocument. Try something like this:

QTextDocument text;
text.setHtml("<>"");
QString plain = text.toPlainText();
qDebug("%s.", qPrintable(plain));

Remember that QTextDocument needs the gui module.

like image 110
Luca Carlon Avatar answered Sep 28 '22 02:09

Luca Carlon


I think this will solve your problem.

QString escaped= 
QString(myhtml).replace("&","&amp;").replace(">","&gt;").replace("<","&lt;");
like image 26
Sharjeel Alam Avatar answered Sep 28 '22 03:09

Sharjeel Alam