WebView QML Type | Qt WebView | Qt 6.11.1
Description: A component for displaying web content.

- Qt 6.11
- Qt WebView
- QML Types
- WebView
- Qt 6.11.1 Reference Documentation

# WebView QML Type

A component for displaying web content. More...

Import Statement: | `import QtWebView`

- List of all members, including inherited members

## Properties

- canGoBack : bool
- canGoForward : bool
- httpUserAgent : url `(since QtWebView 1.14)`
- loadProgress : int
- loading : bool
- settings : WebViewSettings `(since QtWebView 6.5)`
- title : string
- url : url

## Signals

- cookieAdded(string domain, string name)
- cookieRemoved(string domain, string name)
- httpUserAgentChanged(string userAgent)
- loadProgressChanged(int loadProgress)
- loadingChanged(WebViewLoadRequest loadRequest)
- titleChanged(string title)
- urlChanged(url url)

## Methods

- 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()

## Detailed Description

WebView is a component for displaying web content which is implemented using native APIs on the platforms where this is available, thus it does not necessarily require including a full web browser stack as part of the application.

To make the Qt WebView module function correctly across all platforms, it is necessary to call QtWebView::initialize() right after creating the QGuiApplication instance.

Note: Due to platform limitations overlapping the WebView and other QML components is not supported.

## Property Documentation

### canGoBack : bool `[read-only]`

Holds `true` if it's currently possible to navigate back in the web history.

### canGoForward : bool `[read-only]`

Holds `true` if it's currently possible to navigate forward in the web history.

### httpUserAgent : url `[since QtWebView 1.14]`

The user agent in use.

This property was introduced in QtWebView 1.14.

### loadProgress : int `[read-only]`

The current load progress of the web content, represented as an integer between 0 and 100.

### loading : bool `[read-only]`

Holds `true` if the WebView is currently in the process of loading new content, `false` otherwise.

See also loadingChanged().

### settings : WebViewSettings `[read-only, since QtWebView 6.5]`

Settings object for the WebView.

This property was introduced in QtWebView 6.5.

See also WebViewSettings.

### title : string `[read-only]`

The title of the currently loaded web page.

### url : url

The URL of currently loaded web page. Changing this will trigger loading new content.

The URL is used as-is. URLs that originate from user input should be parsed with QUrl::fromUserInput().

Note: The WebView does not support loading content through the Qt Resource system.

## Signal Documentation

### cookieAdded(string domain, string name)

This signal is emitted when a cookie is added.

The parameters provide information about the domain and the name of the added cookie.

Note: When Qt WebEngine module is used as backend, cookieAdded signal will be emitted for any cookie added to the underlying QWebEngineCookieStore, including those added by websites. In other cases cookieAdded signal is only emitted for cookies explicitly added with setCookie().

Note: The corresponding handler is `onCookieAdded`.

### cookieRemoved(string domain, string name)

This signal is emitted when a cookie is deleted.

The parameters provide information about the domain and the name of the deleted cookie.

Note: The corresponding handler is `onCookieRemoved`.

### httpUserAgentChanged(string userAgent)

This signal is emitted whenever the userAgent of the view changes.

Note: The corresponding handler is `onHttpUserAgentChanged`.

See also httpUserAgent.

### 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: The corresponding handler is `onLoadProgressChanged`.

See also loadingChanged.

### loadingChanged(WebViewLoadRequest loadRequest)

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 loadRequest parameter holds the url and status of the request, as well as an errorString containing an error message for a failed request.

Note: The corresponding handler is `onLoadingChanged`.

See also WebViewLoadRequest.

### titleChanged(string title)

This signal is emitted whenever the title of the view changes.

Note: The corresponding handler is `onTitleChanged`.

See also title.

### urlChanged(url url)

This signal is emitted whenever the url of the view changes.

Note: The corresponding handler is `onUrlChanged`.

See also url.

## Method Documentation

### `[since QtWebView 6.3]` void deleteAllCookies()

Deletes all the cookies.

This method was introduced in QtWebView 6.3.

### `[since QtWebView 6.3]` void deleteCookie(string domain, string name)

Deletes a cookie with the specified domain and name.

The cookieRemoved signal will be emitted when the cookie is deleted.

This method was introduced in QtWebView 6.3.

### void goBack()

Navigates back in the web history.

### void goForward()

Navigates forward in the web history.

### void loadHtml(string html, url baseUrl)

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 WebView does not support loading content through the Qt Resource system.

See also url.

### void reload()

Reloads the current url.

### void runJavaScript(string script, variant callback)

Runs the specified JavaScript. In case a callback function is provided, it will be invoked after the script finished running.

     runJavaScript("document.title", function(result) { console.log(result); });

### `[since QtWebView 6.3]` void setCookie(string domain, string name, string value)

Adds a cookie with the specified domain, name and value.

The cookieAdded signal will be emitted when the cookie is added.

This method was introduced in QtWebView 6.3.

### void stop()

Stops loading the current url.