0

I have a desktop c++/qt gui app, that is using QWebview as its central widget.

I am struggling to do something which seems fairly trivial. I want to add an element to a web page from qt like the following example

<body>
    <h1>When Are You Going To Fix This</h1>
</body>

to

<body>
    <h1>When Are You Going To Fix This</h1>
    <p>I am doing it now</p>
</body>

I have tried and other variations

//.. Gui set up and url loaded into webview
//  my attempt at adding a new HTML element

QWebFrame * frame   = ui->webView->page()->mainFrame();
QWebElement body   = frame->documentElement().findFirst("BODY");    

if(!body.isNull()){
    QWebElement newElem; //create a new element to 
    newElem.appendInside("<p>I am doing it now</p>");
    newElem.appendInside(body);
}

I have also tried creating a new element and building the desired parts but to no avail

QWebFrame * frame   = ui->webView->page()->mainFrame();
QWebElement body   = frame->documentElement().findFirst("BODY");    

if(!body.isNull()){
    QWebElement newElem; //create a new element to 
    newElem.setAttribute("TAG", "P");
    newElem.setAttribute("innerHTML", "I am doing it now");
    newElem.appendInside(body);
}

Is it possible to do this with the qt webkit or am I missing something blantly obvious..?

user866190
  • 855
  • 5
  • 14
  • 31

1 Answers1

0

I don't know about QWebElements but I'd simply extracted the html as QString with ui->webView()->page()->mainFrame()->toHtml(); then inserted the paragraph to the html and finally loaded the html into QWebView with ui->webView()->setHtml(html);.

headsvk
  • 2,726
  • 1
  • 19
  • 23