公告
财富商城
积分规则
提问
发文
2019-02-11 12:00发布
Ridiculous、
How do I escape/sanitize a QString that contains HTML?
I.e. showInBroswser(escaped(str)) == showInNotepad(str);
showInBroswser(escaped(str)) == showInNotepad(str);
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.
Use QString::toHtmlEscaped()
QString::toHtmlEscaped()
QString src; Qstring html = src.toHtmlEscaped(); showInBrowser(html) == showInNotepad(str);
Reference: http://doc.qt.io/qt-5/qstring.html#toHtmlEscaped
Use Qt::escape.
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
Just to bring this answer up with the times, Qt 5.1 has QString::toHtmlEscaped().
最多设置5个标签!
If you want to insert plain text to a QTextEdit you can use:
and, for example, to modify the color :
And similar for the font or other property of the text...
Hope that helps.
Qt 5
Use
QString::toHtmlEscaped()
Reference: http://doc.qt.io/qt-5/qstring.html#toHtmlEscaped
Qt 4
Use
Qt::escape
.Reference: http://doc.qt.io/qt-4.8/qt.html#escape
Just to bring this answer up with the times, Qt 5.1 has
QString::toHtmlEscaped()
.