In my Qt project, I want to find the text content in QWebView. I have tried the QWebElement method, but it failed.
My html is:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>nothing</title>
<style>
input[type=text] { font-size:15px; width:200; background:#ccc}
</style>
</head>
<p> hello </p>
<body>
<input type='text' name='hello' value='good luck'/>
</body>
</html>
Now, I want to edit this html, for example, I want the text display "hello, qt". And my code is:
QWebView * webView = new QWebView();
webView->load(QUrl::fromLocalFile("C:\\Users\\zhq\\Desktop\\QT_VTK_MIP\\qt.html"));
QWebElement document = webView->page()->currentFrame()->documentElement();
QWebElement firstTextInput = document.findFirst("input[type=text]");
QString storedText = firstTextInput.attribute("value");
firstTextInput.setAttribute("value",QString("hello,qt"));
webView->show();
However, the html can be display normally by QWebView, but the text content has not been modified as "hello, qt".
After debugging the code, I find the findFirst function return a NULL value. So, what's wrong with the findFirst function.
And, what if several text exist in the html? How can I using the name of the text to identify what I actually need?
Any suggestion means a lot for me. Thanks in advance.
ZhQ