how to get the full URL from a QML WebView

288 views Asked by At

When clicking on a link inside of a QT Quick WebView (something like "http://example.com/page?abc=def&bca=fde"), the url property doesn't contain the query string (giving only "http://example.com/page").

I tried console.log(webView.url) (webView being the ID of my WebView component) expecting it to be "http://example.com/page?abc=def&bca=fde", the result was "http://example.com/page" instead

Is there a way to get the query part?

1

There are 1 answers

1
iam_peter On

I don't know exactly what you are doing, but it works correctly in my example. I'm using Qt 6.4.0.

Steps to reproduce:

  1. Start example application

  2. Type in qt in the google search field

  3. Hit enter

  4. Click on the image tab

  5. View link with query part

The output will look as follows

qml: URL https://www.google.com/search?q=qt&source=lnms&tbm=isch&sa=X&ved=2ahUKEwiLxPKM4NX8AhVzS_EDHXYmAkwQ_AUoAXoECAEQAw&biw=800&bih=600
qml: LOAD https://www.google.com/search?q=qt&source=lnms&tbm=isch&sa=X&ved=2ahUKEwiLxPKM4NX8AhVzS_EDHXYmAkwQ_AUoAXoECAEQAw&biw=800&bih=600

Here is the code

import QtQuick
import QtWebView

Window {
    id: root
    width: 800
    height: 600
    visible: true
    title: qsTr("Hello WebView")

    WebView {
        id: webView
        anchors.fill: parent
        url: "https://www.google.com"

        onUrlChanged: console.log("URL", webView.url)
        onLoadingChanged: function(loadRequest) {
            console.log("LOAD", loadRequest.url)
            if (loadRequest.errorString)
                console.error(loadRequest.errorString);
        }
    }
}