QWebView Change Html Text
-
I load a local file:
ui->webView->load( QUrl( url ) );
The HTML has this div tag:
<div>CustomerName</div>
I want to change CustomerName to John Doe. What's the best way to do this?
-
Hi @IChooseYou and Welcome,
AFAIK you can use QWebElement and QWebFrame to do so.QWebElement
hasfind*
methods (findAll and findFirst) which can be used find the collection of elemets or the exact particular element. Then later once you found out that particularQWebElement
you can invoke its methods like setPlainText or tagName.
So for eg: in your case you can provide aid
to thediv
element using which you can find that element<div id=custname>CustomerName</div> //finding that element QWebElement document = webview->page()->mainFrame()->documentElement(); QWebElement element = document.findFirst("div#custname"); element.setPlainText("John Doe");