- Qt 5.5
- Qt WebEngine
- QML Types
- WebEngineView QML Type
- Qt 5.5.1 Reference Documentation

# WebEngineView QML Type

A WebEngineView renders web content within a QML application. More...

Import Statement: | import QtWebEngine 1.1
Since: | QtWebEngine 1.0

- List of all members, including inherited members

## Properties

- ErrorDomain : enumeration
- Feature : enumeration
- FindFlags : enumeration
- JavaScriptConsoleMessageLevel : enumeration
- LoadStatus : enumeration
- NewViewDestination : enumeration
- canGoBack : bool
- canGoForward : bool
- icon : url
- isFullScreen : bool
- loadProgress : int
- loading : bool
- navigationHistory : WebEngineHistory
- profile : WebEngineProfile
- settings : WebEngineSettings
- title : string
- url : url
- userScripts : list<WebEngineScript>
- webChannel : QQmlWebChannel
- zoomFactor : real

## Signals

- certificateError(error)
- featurePermissionRequested(url securityOrigin, Feature feature)
- fullScreenRequested(WebEngineFullScreenRequest request)
- javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level, message, lineNumber, sourceID)
- linkHovered(hoveredUrl)
- loadingChanged(loadRequest)
- newViewRequested(request)

## Methods

- void findText(string subString, FindFlags options, variant resultCallback)
- void findText(string subString, FindFlags options)
- void findText(string subString)
- void fullScreenCancelled()
- void goBack()
- void goBackOrForward(int offset)
- void goForward()
- grantFeaturePermission(url securityOrigin, Feature feature, bool granted)
- void loadHtml(string html, url baseUrl)
- void reload()
- void reloadAndBypassCache()
- void runJavaScript(string script, variant callback)
- void stop()

## Detailed Description

## Property Documentation

ErrorDomain : enumeration

This enumeration details various high-level error types.

Constant | Description
--- | ---
`WebEngineView::NoErrorDomain` |
`WebEngineView::InternalErrorDomain` | Content fails to be interpreted by Qt WebEngine.
`WebEngineView::ConnectionErrorDomain` | Error results from faulty network connection.
`WebEngineView::CertificateErrorDomain` | Error related to the SSL/TLS certficate.
`WebEngineView::HttpErrorDomain` | Error related to the HTTP connection.
`WebEngineView::FtpErrorDomain` | Error related to the FTP connection.
`WebEngineView::DnsErrorDomain` | Error related to the DNS connection.

Feature : enumeration

This enum describes the platform feature access categories that the user may be asked to grant or deny access to.

Constant | Description
--- | ---
`Geolocation` | Access to location hardware or service
`MediaAudioCapture` | Audio capture devices such a microphones
`MediaVideoCapture` | Video devices, e.g. cameras
`MediaAudioVideoCapture` | Both Audio and Video capture devices.

See also WebEngineView::featurePermissionRequested and WebEngineView::grantFeaturePermission.

FindFlags : enumeration

This enum describes the options available to the findText() function. The options can be OR-ed together from the following list:

Constant | Description
--- | ---
`FindBackward` | Searches backwards instead of forwards.
`FindCaseSensitively` | By default findText() works case insensitive. Specifying this option changes the behavior to a case sensitive find operation.

See also WebEngineView::findText().

JavaScriptConsoleMessageLevel : enumeration

Indicates the severity of a JavaScript console message.

Constant | Description
--- | ---
InfoMessageLevel | Message is purely informative and should be safe to ignore.
WarningMessageLevel | Message indicates there might be a problem that may need attention.
ErrorMessageLevel | Message indicates there has been an error.

LoadStatus : enumeration

Reflects a page's load status.

Constant | Description
--- | ---
LoadStartedStatus | Page is currently loading.
LoadSucceededStatus | Page has successfully loaded, and is not currently loading.
LoadFailedStatus | Page has failed to load, and is not currently loading.

NewViewDestination : enumeration

This enumeration details the format in which a new view request should be opened.

Constant | Description
--- | ---
`WebEngineView::NewViewInWindow` | The page expects to be opened in a separate Window.
`WebEngineView::NewViewInTab` | The page expects to be opened in a tab of the same window.
`WebEngineView::NewViewInDialog` | The page expects to be opened in a Window without any tab, tool or URL bar.
`WebEngineView::NewViewInBackgroundTab` | The page expects to be opened in a tab of the same window, without hiding the currently visible WebEngineView.

See also WebEngineNewViewRequest::destination.

read-onlycanGoBack : bool

Returns `true` if there are prior session history entries, `false` otherwise.

read-onlycanGoForward : bool

Returns `true` if there are subsequent session history entries, `false` otherwise.

read-onlyicon : url

This property holds the location of the currently displaying web site icon, also known as favicon or shortcut icon. This read-only URL corresponds to the image used within a mobile browser application to represent a bookmarked page on the device's home screen.

The following snippet uses the `icon` property to build an `Image` component:

    Image {
        id: appIcon
        source: webView.icon != "" ? webView.icon : "fallbackFavIcon.png";
        ...
    }

read-onlyisFullScreen : bool

Returns `true` if the web view is in fullscreen mode, `false` otherwise.

This QML property was introduced in QtWebEngine 1.1.

See also WebEngineView::fullScreenRequested and WebEngineView::fullScreenCancelled.

read-onlyloadProgress : int

This property holds the amount of the page that has been loaded, expressed as an integer percentage in the range from `0` to `100`.

read-onlyloading : bool

Returns `true` if the HTML page is currently loading, `false` otherwise.

read-onlynavigationHistory : WebEngineHistory

The navigation history of the current view.

This QML property was introduced in QtWebEngine 1.1.

See also WebEngineHistory.

profile : WebEngineProfile

The current profile used for the view.

This QML property was introduced in QtWebEngine 1.1.

See also WebEngineProfile.

read-onlysettings : WebEngineSettings

Settings used by this view.

This QML property was introduced in QtWebEngine 1.1.

See also WebEngineSettings.

read-onlytitle : string

This property holds the title of the currently displaying HTML page, a read-only value that reflects the contents of the `<title>` tag.

url : url

The location of the currently displaying HTML page. This writable property offers the main interface to load a page into a web view. It functions the same as the `window.location` DOM property.

See also WebEngineView::loadHtml().

read-onlyuserScripts : list<WebEngineScript>

List of script objects attached to the view.

webChannel : QQmlWebChannel

The web channel instance used by this view. This channel is automatically using the internal QtWebEngine transport mechanism over Chromium IPC, and exposed in the javascript context of the page it is rendering as `qt.webChannelTransport`. This transport object is used when instantiating the JavaScript counterpart of QWebChannel using the Qt WebChannel JavaScript API.

Note: The view does not take ownership for an assigned webChannel object.

This QML property was introduced in QtWebEngine 1.1.

zoomFactor : real

Zoom factor for the view. Valid values are within the range from `0.25` to `5.0`. The default factor is `1.0`.

This QML property was introduced in QtWebEngine 1.1.

## Signal Documentation

certificateError(error)

This signal is emitted when an invalid certificate error is raised while loading a given request.

The certificate error can be rejected by calling WebEngineCertificateError::rejectCertificate, which will stop loading the request.

The certificate error can be ignored by calling WebEngineCertificateError::ignoreCertificateError which will resume loading the request.

It is possible to defer the decision of rejecting the given certificate by calling WebEngineCertificateError::defer, which is useful when waiting for user input. By default the invalid certificate will be automatically rejected.

The corresponding handler is onCertificateError.

This QML signal was introduced in QtWebEngine 1.1.

See also WebEngineCertificateError.

featurePermissionRequested(url securityOrigin, Feature feature)

This is signal is emitted when the web site identified by securityOrigin requests to make use of the resource or device identified by feature.

See also WebEngineView::grantFeaturePermission.

fullScreenRequested(WebEngineFullScreenRequest request)

This signal is emitted when the web page requests fullscreen mode through the JavaScript API.

The corresponding handler is onFullScreenRequested.

This QML signal was introduced in QtWebEngine 1.1.

See also WebEngineFullScreenRequest and WebEngineView::isFullScreen.

javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level, message, lineNumber, sourceID)

This signal is emitted when a JavaScript program tries to print a message to the web browser's console.

For example in case of evaluation errors the source URL may be provided in sourceID as well as the lineNumber.

level indicates the severity of the event that triggered the message, i.e. if it was triggered by an error or a less severe event.

The corresponding handler is onJavaScriptConsoleMessage.

linkHovered(hoveredUrl)

Within a mouse-driven interface, this signal is emitted when a mouse pointer passes over a link, corresponding to the `mouseover` DOM event. This event may also occur in touch interfaces for `mouseover` events that are not cancelled with `preventDefault()`. hoveredUrl provides the link's location.

The corresponding handler is onLinkHovered.

loadingChanged(loadRequest)

This signal is emitted when a page load begins, ends, or fails. The corresponding handler is onLoadingChanged.

When handling the signal with onLoadingChanged, various read-only parameters are available on the loadRequest:

Property | Description
--- | ---
url | The location of the resource that is loading.
status | Reflects one of four load states: `WebEngineView::LoadStartedStatus`, `WebEngineView::LoadStoppedStatus`, `WebEngineView::LoadSucceededStatus`, or `WebEngineView::LoadFailedStatus`. See WebEngineLoadRequest::status and WebEngineView::LoadStatus.
errorString | The description of load error.
errorCode | The HTTP error code.
errorDomain | The high-level error types, one of `WebEngineView::ConnectionErrorDomain`, `WebEngineView::HttpErrorDomain`, `WebEngineView::InternalErrorDomain`, `WebEngineView::DownloadErrorDomain`, or `WebEngineView::NoErrorDomain`. See WebEngineView::ErrorDomain for the full list.

See also WebEngineView::loading.

newViewRequested(request)

This signal is emitted when a page load is requested to happen in a separate WebEngineView. This can either be because the current page requested it explicitly through a JavaScript call to window.open, or because the user clicked on a link while holding Shift, Ctrl or a built-in combination that triggers the page to open in a new window.

If this signal isn't handled the requested load will fail.

An example implementation:

    QtObject {
        id: windowParent
        // Create the initial browsing windows and open the startup page.
        Component.onCompleted: {
            var firstWindow = windowComponent.createObject(windowParent)
            firstWindow.webView.loadHtml('<input type="button" value="Click!" onclick="window.open(&quot;http://qt.io&quot;)">')
        }

        property Component windowComponent: Window {
            // Destroy on close to release the Window's QML resources.
            // Because it was created with a parent, it won't be garbage-collected.
            onClosing: destroy()
            visible: true

            property WebEngineView webView: webView_
            WebEngineView {
                id: webView_
                anchors.fill: parent

                // Handle the signal. Dynamically create the window and
                // use its WebEngineView as the destination of our request.
                onNewViewRequested: {
                    var newWindow = windowComponent.createObject(windowParent)
                    request.openIn(newWindow.webView)
                }
            }
        }
    }

The corresponding handler is onNewViewRequested.

This QML signal was introduced in QtWebEngine 1.1.

See also WebEngineNewViewRequest, WebEngineView::NewViewDestination, and WebEngine Quick Nano Browser.

## Method Documentation

void findText(string subString, FindFlags options, variant resultCallback)

Finds the specified string, subString, in the page, using the given options.

To clear the selection, just pass an empty string.

The resultCallback must take a boolean parameter. It will be called with a value of true if the subString was found; otherwise the callback value will be false.

    findText("Qt", WebEngineView.FindCaseSensitively, function(success) {
        if (success)
            console.log("Qt was found!");
    });

This QML method was introduced in QtWebEngine 1.1.

void findText(string subString, FindFlags options)

Finds the specified string, subString, in the page, using the given options.

To clear the selection, just pass an empty string.

    findText("Qt", WebEngineView.FindBackward | WebEngineView.FindCaseSensitively);

This QML method was introduced in QtWebEngine 1.1.

void findText(string subString)

Finds the specified string, subString, in the page.

To clear the selection, just pass an empty string.

This QML method was introduced in QtWebEngine 1.1.

void fullScreenCancelled()

Immediately sets `isFullScreen` property to `false`. It can be used to notify the browser engine when the windowing system forces the application to leave fullscreen mode.

    ApplicationWindow {
        onVisibilityChanged: {
            if (webEngineView.isFullScreen && visibility != Window.FullScreen)
                webEngineView.fullScreenCancelled()
        }

        WebEngineView {
            id: webEngineView
            ...
        }
    }

This QML method was introduced in QtWebEngine 1.1.

See also WebEngineView::isFullScreen and WebEngineView::fullScreenRequested.

void goBack()

Go backward within the browser's session history, if possible. This function is equivalent to the `window.history.back()` DOM method.

See also WebEngineView::canGoBack.

void goBackOrForward(int offset)

If offset is positive, goes forward the specified number of offset pages in the current session history. If offset is negative, it goes back. If the offset is invalid, the page is not changed.

This QML method was introduced in QtWebEngine 1.1.

See also WebEngineView::goBack and WebEngineView::goForward.

void goForward()

Go forward within the browser's session history, if possible. This function is equivalent to the `window.history.forward()` DOM method.

grantFeaturePermission(url securityOrigin, Feature feature, bool granted)

Sets the permission for the web site identified by securityOrigin to use feature.

This QML method was introduced in QtWebEngine 1.1.

See also WebEngineView::featurePermissionRequested.

void loadHtml(string html, url baseUrl)

Loads the specified html as the content of 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`.

See also WebEngineView::url.

void reload()

Reloads the current page. This function is equivalent to the `window.location.reload()` DOM method.

See also WebEngineView::reloadAndBypassCache.

void reloadAndBypassCache()

Reloads the current page, ignoring any cached content.

See also WebEngineView::reload.

void runJavaScript(string script, variant callback)

Runs the specified script in the content of the web view.

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

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

void stop()

Stops loading the current page.