How can I make a QString html-escaped

不打扰是莪最后的温柔 提交于 2019-11-30 17:03:28
PenguinCoder

Qt 5

Use QString::toHtmlEscaped()

QString src;
Qstring html = src.toHtmlEscaped();
showInBrowser(html) == showInNotepad(str);

Reference: http://doc.qt.io/qt-5/qstring.html#toHtmlEscaped

Qt 4

Use Qt::escape.

#include <QtGui/qtextdocument.h>

QString src;
Qstring html = Qt::escape(src);
showInBrowser(html) == showInNotepad(str);

Reference: http://doc.qt.io/qt-4.8/qt.html#escape

gremwell

Just to bring this answer up with the times, Qt 5.1 has QString::toHtmlEscaped().

If you want to insert plain text to a QTextEdit you can use:

void QTextEdit::insertPlainText ( const QString & text );

and, for example, to modify the color :

void QTextEdit::setTextColor ( const QColor & c ); 

And similar for the font or other property of the text...

Hope that helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!