2009-12-24 87 views
2

嗨有人可以幫我找到文檔(我不確定要尋找什麼),以便能夠使用Qt Webkit更改網頁上的輸入文本框內的文本 - 我基本上想做一個功能所以人們可以記住他們在網頁上的輸入並保存爲預設.. 一旦預設被點擊 - 自動填寫。Qt Webkit - 自動完成一個輸入

回答

5

我相信你可以使用QWebFrame對象來訪問你的網頁的元素集合後,它的加載; QWebFrame通過QWebView的page()方法爲您提供。有關詳細信息,請參閱下面的示例;它加載谷歌的網頁,並插入值到搜索文本框:

... 
// connect the load finished signal of the webview 
QWebView::connect(ui->webView, SIGNAL(loadFinished(bool)), this, SLOT(on_pageLoad_finished(bool))); 
// load a webpage 
QUrl url("http://www.google.com/"); 
ui->webView->load(url); 
... 

on_pageLoad_finished信號實現:

void MainWindow::on_pageLoad_finished(bool ok) 
{ 
    if (ok) 
    { 
     QWebFrame* frame = ui->webView->page()->currentFrame(); 
     if (frame!=NULL) 
     { 
      // get collection of the input web elements with name set to "q" 
      // this function was introduced in Qt 4.6. 
      QWebElementCollection collection = frame->findAllElements("input[name=q]"); 
      foreach (QWebElement element, collection) 
       element.setAttribute("value", "qt webkit autocomplete an input"); 
     } 
    } 
} 

希望這會有所幫助,至於

+0

我知道你這個答案就像一個十億年舊的,但是你知道如何在填寫值之後實際提交表單嗎?那麼基本上如何點擊「提交」按鈕? – 2012-04-19 18:37:12