WebView QML Type
用于显示网页内容的组件。更多
Import Statement: | import QtWebView |
属性
- canGoBack : bool
- canGoForward : bool
- httpUserAgent : url
(since QtWebView 1.14)
- loadProgress : int
- loading : bool
- settings : WebViewSettings
(since QtWebView 6.5)
- title : string
- url : url
信号
- cookieAdded(string domain, string name)
- cookieRemoved(string domain, string name)
- loadingChanged(WebViewLoadRequest loadRequest)
方法
- void deleteAllCookies()
(since QtWebView 6.3)
- void deleteCookie(string domain, string name)
(since QtWebView 6.3)
- void goBack()
- void goForward()
- void loadHtml(string html, url baseUrl)
- void reload()
- void runJavaScript(string script, variant callback)
- void setCookie(string domain, string name, string value)
(since QtWebView 6.3)
- void stop()
详细说明
WebView 是一个用于显示网络内容的组件,在可用的平台上使用本地 API 实现,因此不一定需要在应用程序中包含完整的网络浏览器栈。
为使Qt WebView 模块在所有平台上正常运行,有必要在创建QGuiApplication 实例后立即调用QtWebView::initialize() 。
注: 由于平台限制,不支持将 WebView 与其他 QML 组件重叠。
属性文档
canGoBack : bool |
如果当前可以回溯网页历史,则保持true
。
canGoForward : bool |
如果当前可以在网页历史记录中向前导航,则保留true
。
httpUserAgent : url |
使用中的用户代理。
注意: 在 WinRT 上,此属性会影响应用程序的所有 WebView。
该属性在 QtWebView 1.14 中引入。
loadProgress : int |
网页内容的当前加载进度,以 0 到 100 之间的整数表示。
loading : bool |
如果WebView 当前正在加载新内容,则持有true
,否则持有false
。
另请参阅 loadingChanged() 。
settings : WebViewSettings |
title : string |
当前加载的网页标题。
url : url |
当前加载的网页的 URL。更改它将触发加载新内容。
URL 将按原样使用。源于用户输入的 URL 应使用QUrl::fromUserInput() 进行解析。
注意: WebView 不支持通过 Qt XML 资源系统加载内容。
信号文档
该信号在添加 cookie 时发出。
参数提供了关于所添加 cookie 的domain 和name 的信息。
注意: 当 QtWebEngine 模块被用作后端时,cookieAdded 信号将对任何添加到底层QWebEngineCookieStore 的 cookie(包括网站添加的 cookie)发出。在其他情况下,只有使用setCookie() 明确添加的 cookie 才会发出 cookieAdded 信号。
注: 相应的处理程序是onCookieAdded
。
该信号在 cookie 被删除时发出。
参数提供了关于已删除 cookie 的domain 和name 的信息。
注: 相应的处理程序是onCookieRemoved
。
loadingChanged(WebViewLoadRequest loadRequest) |
当加载网页内容的状态发生变化时,会发出该信号。例如,通过处理该信号,可以对页面加载错误做出反应。
loadRequest 参数包含请求的url和状态,以及请求失败时包含错误信息的errorString。
注: 相应的处理程序是onLoadingChanged
。
另请参阅 WebViewLoadRequest 。
方法文档
|
删除所有 cookie。
此方法在 QtWebView 6.3 中引入。
void goBack() |
在网页历史中向后转。
void goForward() |
在网页历史中向前导航。
void reload() |
重新加载当前的url 。
运行指定的 JavaScript。如果提供了callback 函数,它将在script 运行完成后被调用。
runJavaScript("document.title", function(result) { console.log(result); });
void stop() |
停止加载当前的url 。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.