Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make a QString html-escaped

How do I escape/sanitize a QString that contains HTML?

I.e. showInBroswser(escaped(str)) == showInNotepad(str);

like image 215
sashoalm Avatar asked Jan 05 '13 15:01

sashoalm


1 Answers

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

like image 156
PenguinCoder Avatar answered Sep 20 '22 11:09

PenguinCoder