简体   繁体   中英

how to get the full URL from a QML WebView

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM