我怎样才能让一个QString html转义 [英] How can I make a QString html-escaped
本文介绍了我怎样才能让一个QString html转义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何转义/清理包含HTML的QString?
How do I escape/sanitize a QString that contains HTML?
I.e。 showInBroswser(escape(str))== showInNotepad(str);
I.e. showInBroswser(escaped(str)) == showInNotepad(str);
推荐答案
< h2> Qt 5
使用 QString :: toHtmlEscaped()
QString src;
Qstring html = src.toHtmlEscaped();
showInBrowser(html) == showInNotepad(str);
参考: http://doc.qt.io/qt-5/qstring.html#toHtmlEscaped
使用 Qt :: escape
。
#include <QtGui/qtextdocument.h>
QString src;
Qstring html = Qt::escape(src);
showInBrowser(html) == showInNotepad(str);
参考: http://doc.qt.io/qt-4.8/qt.html#escape
这篇关于我怎样才能让一个QString html转义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文