WebEngineView QML Type

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

Import Statement: import QtWebEngine 1.1
Since: QtWebEngine 1.0

Properties

Signals

Methods

Detailed Description

Property Documentation

ErrorDomain : enumeration

This enumeration details various high-level error types.

ConstantDescription
WebEngineView::NoErrorDomain 
WebEngineView::InternalErrorDomainContent fails to be interpreted by Qt WebEngine.
WebEngineView::ConnectionErrorDomainError results from faulty network connection.
WebEngineView::CertificateErrorDomainError related to the SSL/TLS certficate.
WebEngineView::HttpErrorDomainError related to the HTTP connection.
WebEngineView::FtpErrorDomainError related to the FTP connection.
WebEngineView::DnsErrorDomainError 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.

ConstantDescription
GeolocationAccess to location hardware or service
MediaAudioCaptureAudio capture devices such a microphones
MediaVideoCaptureVideo devices, e.g. cameras
MediaAudioVideoCaptureBoth 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:

ConstantDescription
FindBackwardSearches backwards instead of forwards.
FindCaseSensitivelyBy 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.

ConstantDescription
InfoMessageLevelMessage is purely informative and should be safe to ignore.
WarningMessageLevelMessage indicates there might be a problem that may need attention.
ErrorMessageLevelMessage indicates there has been an error.

LoadStatus : enumeration

Reflects a page's load status.

ConstantDescription
LoadStartedStatusPage is currently loading.
LoadSucceededStatusPage has successfully loaded, and is not currently loading.
LoadFailedStatusPage 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.

ConstantDescription
WebEngineView::NewViewInWindowThe page expects to be opened in a separate Window.
WebEngineView::NewViewInTabThe page expects to be opened in a tab of the same window.
WebEngineView::NewViewInDialogThe page expects to be opened in a Window without any tab, tool or URL bar.
WebEngineView::NewViewInBackgroundTabThe 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.


The navigation history of the current view.

This QML property was introduced in QtWebEngine 1.1.

See also WebEngineHistory.


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:

PropertyDescription
urlThe location of the resource that is loading.
statusReflects one of four load states: WebEngineView::LoadStartedStatus, WebEngineView::LoadStoppedStatus, WebEngineView::LoadSucceededStatus, or WebEngineView::LoadFailedStatus. See WebEngineLoadRequest::status and WebEngineView::LoadStatus.
errorStringThe description of load error.
errorCodeThe HTTP error code.
errorDomainThe 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.


© 2016 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.