0
在我的Qt項目中,我想查找QWebView中的文本內容。我嘗試過QWebElement方法,但失敗了。在QWebView中查找文本內容失敗
我的HTML是:
<!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>
現在,我想編輯這個網站,比如我想要的文字顯示 「Hello,QT」。而我的代碼是:
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();
但是,HTML可以顯示通常由QWebView,但文字內容不被修改爲:「你好,QT」。
調試代碼後,我找到的FindFirst函數返回NULL值。那麼,findFirst函數有什麼問題。
而且,如果幾個文本在HTML中存在哪些?我如何使用文本的名稱來確定我實際需要的內容?
任何建議對我來說都意味着很多。提前致謝。
ZHQ