Qt Webkit - 自动完成输入

时间:2009-12-24 17:05:21

标签: qt webkit

嗨,有人可以帮我找到文档(我不确定要查找什么)能够使用Qt Webkit更改WebPage上的输入文本框内的文本 - 我想基本上创建一个功能,以便人们可以记住他们的输入在网页上保存为预设.. 单击预设后 - 自动填写。

1 个答案:

答案 0 :(得分:5)

我相信您可以使用QWebFrame对象来访问加载后页面的Web元素集合; 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");
        }
    }
}

希望这有帮助,尊重