[英]how to get the full URL from a QML WebView
單擊 QT Quick url
中的鏈接時(類似於“http://example.com/page?abc=def&bca=fde”),url 屬性不包含查詢字符串(僅提供“http:/ /example.com/page”)。
我嘗試了console.log(webView.url)
(webView 是我的 WebView 組件的 ID)期望它是“http://example.com/page?abc=def&bca=fde”,結果是“http:// example.com/page" 代替
有沒有辦法獲取查詢部分?
我不確切知道你在做什么,但它在我的例子中工作正常。 我正在使用 Qt 6.4.0。
重現步驟:
啟動示例應用程序
在谷歌搜索字段中輸入 qt
按回車鍵
單擊圖像選項卡
查看帶有查詢部分的鏈接
output 將如下所示
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
這是代碼
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);
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.