"; QWebFrame* frame = htmlProcessor.mainFrame(); frame->setHtml" /> "; QWebFrame* frame = htmlProcessor.mainFrame(); frame->setHtml" /> "; QWebFrame* frame = htmlProcessor.mainFrame(); frame->setHtml"/>

QWebFrame export xhtml

40 views Asked by At

We abuse the QWebFrame as a html parser

QString html = "<img src=\"input_213123dfh\" />";
QWebFrame* frame = htmlProcessor.mainFrame();
frame->setHtml(html);
QWebElementCollection inputs = frame->documentElement().findAll("img[src*=input_]");
foreach (QWebElement input, inputs) {
    input.setOuterXml(QString("<input type=\"text\" uuid=\"%1\" />").arg(input.attribute("src").section("_",1,1)));
}
html = frame->toHtml();

which outputs

<html><head></head><body><input type="text" uuid="213123dfh"></body></html>

our Problem is that the input tag in the output is not self-closing. Is it possible to get html with self-closed tags?

1

There are 1 answers

0
Kuba hasn't forgotten Monica On

This is a dead-end. It won't be portable to QWebEngine and as you can see it doesn't quite work.

Instead, you should iterate the DOM from javascript, and you can emit the xhtml there.