QWebView Class
The QWebView class provides a window that is used to view web content. More...
| Header: | #include <QWebView> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS WebView)target_link_libraries(mytarget PRIVATE Qt6::WebView) |
| qmake: | QT += webview |
| Since: | Qt 6.11 |
| Inherits: | QWindow |
Properties
|
Public Functions
| bool | canGoBack() const |
| bool | canGoForward() const |
| void | deleteAllCookies() |
| void | goBack() |
| void | goForward() |
| QString | httpUserAgent() const |
| bool | isLoading() const |
| void | loadHtml(const QString &html, const QUrl &baseUrl = QUrl()) |
| int | loadProgress() const |
| void | reload() |
| void | setHttpUserAgent(const QString &httpUserAgent) |
| void | setUrl(const QUrl &url) |
| QWebViewSettings * | settings() const |
| void | stop() |
| QString | title() const |
| QUrl | url() const |
Signals
| void | httpUserAgentChanged(const QString &userAgent) |
| void | loadProgressChanged(int loadProgress) |
| void | loadingChanged(const QWebViewLoadingInfo &loadingInfo) |
| void | titleChanged(const QString &title) |
| void | urlChanged(const QUrl &url) |
Detailed Description
A web view is a window for displaying web content that is implemented using native APIs on the platforms where they are available. Therefore, it does not necessarily require including a full web browser stack as part of the application.
A web site can be loaded to a web view with the setUrl() function.
Alternatively, if you have the HTML content readily available, you can use setHtml() instead.
The loadingChanged() signal is emitted when the view begins loading and when the view has been loaded completely. Its argument QWebViewLoadRequest object indicates whether loading was successful or failed.
The title of an HTML document can be accessed with the title() property.
Property Documentation
[read-only] canGoBack : bool
Holds true if it's currently possible to navigate back in the web history.
Access functions:
| bool | canGoBack() const |
Notifier signal:
| void | loadingChanged(const QWebViewLoadingInfo &loadingInfo) |
[read-only] canGoForward : bool
Holds true if it's currently possible to navigate forward in the web history.
Access functions:
| bool | canGoForward() const |
Notifier signal:
| void | loadingChanged(const QWebViewLoadingInfo &loadingInfo) |
httpUserAgent : QString
This property holds the user agent in use. The user-agent string sent with HTTP to identify the browser.
Access functions:
| QString | httpUserAgent() const |
| void | setHttpUserAgent(const QString &httpUserAgent) |
Notifier signal:
| void | httpUserAgentChanged(const QString &userAgent) |
[read-only] loadProgress : int
The current load progress of the web content, represented as an integer between 0 and 100.
Access functions:
| int | loadProgress() const |
Notifier signal:
| void | loadProgressChanged(int loadProgress) |
[read-only] loading : bool
Holds true if the WebView is currently in the process of loading new content, false otherwise.
Access functions:
| bool | isLoading() const |
Notifier signal:
| void | loadingChanged(const QWebViewLoadingInfo &loadingInfo) |
[read-only] settings : QWebViewSettings* const
Settings object for the QWebView. The settings for a web view.
Access functions:
| QWebViewSettings * | settings() const |
See also WebViewSettings.
title : QString
This property holds the title of the currently loaded web page.
The title of the page as defined by the HTML <title> element.
Access functions:
| QString | title() const |
Notifier signal:
| void | titleChanged(const QString &title) |
See also titleChanged().
url : QUrl
This property holds the URL of the web page currently viewed.
Setting this property clears the view and loads the URL. By default, this property contains an empty, invalid URL. URLs that originate from user input should be parsed with QUrl::fromUserInput().
Note: QWebView does not support loading content through the Qt Resource system.
Access functions:
| QUrl | url() const |
| void | setUrl(const QUrl &url) |
Notifier signal:
| void | urlChanged(const QUrl &url) |
See also loadingChanged().
Member Function Documentation
[invokable] void QWebView::deleteAllCookies()
Deletes all the cookies.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
[invokable] void QWebView::goBack()
Navigates back in the web history.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
[invokable] void QWebView::goForward()
Navigates forward in the web history.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
[signal] void QWebView::httpUserAgentChanged(const QString &userAgent)
This signal is emitted whenever the userAgent of the view changes.
Note: Notifier signal for property httpUserAgent.
See also httpUserAgent().
[invokable] void QWebView::loadHtml(const QString &html, const QUrl &baseUrl = QUrl())
Loads the specified html content to the web view.
This method offers a lower-level alternative to the url property, which references HTML pages via URL.
External objects such as stylesheets or images referenced in the HTML document should be located relative to baseUrl. For example, if html is retrieved from http://www.example.com/documents/overview.html, which is the base URL, then an image referenced with the relative URL diagram.png, should be at http://www.example.com/documents/diagram.png.
Note: The QWebView does not support loading content through the Qt Resource system.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
[signal] void QWebView::loadProgressChanged(int loadProgress)
This signal is continuously emitted during the loading of a web page. The loadProgress parameter is a value between 0 and 100, indicating what percentage of the web page has been loaded. The intended use for this is to display a progress bar to the user.
Note: Some backends do not support fractional load progress changes, and will only emit this signal at the start and end of a load, with values of 0 and 100, respecively.
Note: Notifier signal for property loadProgress.
See also loadingChanged.
[signal] void QWebView::loadingChanged(const QWebViewLoadingInfo &loadingInfo)
This signal is emitted when the state of loading the web content changes. By handling this signal it's possible, for example, to react to page load errors.
The loadingInfo parameter holds the url and status of the request, as well as an errorString containing an error message for a failed request.
Note: Notifier signal for properties canGoBack, canGoForward, and loading.
See also loadProgressChanged and QWebViewLoadRequest.
[invokable] void QWebView::reload()
Reloads the current url.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
[invokable] void QWebView::stop()
Stops loading the current url.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
[signal] void QWebView::titleChanged(const QString &title)
This signal is emitted whenever the title of the view changes.
Note: Notifier signal for property title.
See also title().
[signal] void QWebView::urlChanged(const QUrl &url)
This signal is emitted whenever the url of the view changes.
Note: Notifier signal for property url.
See also url().
© 2026 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.