Is there an easy way to strip HTML from a QString in Qt?

Nathan Osman picture Nathan Osman · May 10, 2010 · Viewed 16k times · Source

I have a QString with some HTML in it... is there an easy way to strip the HTML from it? I basically want just the actual text content.

<i>Test:</i><img src="blah.png" /><br> A test case

Would become:

Test: A test case

I'm curious to know if Qt has a string function or utility for this.

Answer

k06a picture k06a · May 14, 2011
QString s = "<i>Test:</i><img src=\"blah.png\" /><br> A test case";
s.remove(QRegExp("<[^>]*>"));
// s == "Test: A test case"