tags:

views:

485

answers:

1

Hi can someone help me find the documentation (im unsure what to look for) to be able withint Qt Webkit change the text inside a Input TextBox on a WebPage - i would like basically to make a feature so people could Remember their inputs on a webpage and save as a Preset.. once preset is clicked - auto fill in.

A: 

I believe you can use QWebFrame object to get access to web elements collection of your page after it's loaded; QWebFrame is available for you through page() method of the QWebView. Please see an example below for details; it loads google webpage and inserts value into the search text box:

...
// 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 signal implementation:

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");
        }
    }
}

hope this helps, regards

serge_gubenko