Boggy B
Boggy B

Reputation: 171

Getting a URL from current webpage in Qt WebView

I have a QWebView inside a QTabWidget, and I'd like to know how to get the URL of the web page you're currently on so that I can:

So far, my tabs simply display the first page they load (google.co.uk), but I don't know how to change the name to the current URL when the user clicks a link.

Is there a better way to show the tab name? Or shall I just split the URL and take the name from there?

Upvotes: 0

Views: 731

Answers (3)

david
david

Reputation: 1

you can trigger from the loadFinished event for after a page is loaded

void LoginDialog::on_webViewLogin_loadFinished(bool arg1)
{
    QUrl myurl = ui->webViewLogin->url(); // grab current webview url & show
    //.... other declarations etc
    messageBox.critical( 0, "Error", myurl.toString() );
}

Upvotes: 0

Sprout
Sprout

Reputation: 650

WebView {
    id: webview

    url: "google.co.uk"

    onUrlChanged: {
        console.log("WebView UrlChange: ", url);
        }
    }

Upvotes: 2

souvickcse
souvickcse

Reputation: 7804

view = new QWebView();
connect(view,SIGNAL(linkClicked(QUrl)),this,SLOT(urlchange(QUrl)));

void WebviewItem::urlchange(QUrl &url) 
{
qDebug()<<"linkClicked in Qt "<<url;
 }

Upvotes: 0

Related Questions