0

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 can only think that the webpage that you're going to redirected. This can happen. `webView.url` is both a setter and a getter, so, all redirections will cause `url` to update. To see this, you can implement `onUrlChanged` and console.log all the different values. Perhaps, you can add enough event handling, so you can determine the difference between a click vs a redirect? – Stephen Quan Jan 20 '23 at 21:17

1 Answers1

0

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);
        }
    }
}
iam_peter
  • 3,205
  • 1
  • 19
  • 31
  • This is weird, with google.com it works fine. But if I'm using a custom html page with a link that has a query string it doesn't... It could be that I'm using http instead of https to test my page. For context: I'm using a local webpage served over http (using localhost) to emulate what a real webpage does without sending numerous requests to a server. I want my application to react to what the webview is doing, and for that I need to get the query string. – Farook Al-Sammarraie Jan 20 '23 at 10:16