- Qt 6.11
- Qt WebEngine
- QML Types
- WebEngineHistory
- Qt 6.11.2 Reference Documentation

# WebEngineHistory QML Type

Provides data models that represent the history of a web engine page. More...

Import Statement: | `import QtWebEngine`
Since: | QtWebEngine 1.1
In C++: | QWebEngineHistory

- List of all members, including inherited members

## Properties

- backItems : WebEngineHistoryModel
- forwardItems : WebEngineHistoryModel
- items : WebEngineHistoryModel

## Methods

- void clear() `(since QtWebEngine 1.11)`

## Detailed Description

The WebEngineHistory type can be accessed by using the WebEngineView.history property.

The WebEngineHistory type provides the following WebEngineHistoryModel data model objects:

- `backItems`, which contains the URLs of visited pages.
- `forwardItems`, which contains the URLs of the pages that were visited after visiting the current page.
- `items`, which contains the URLs of the back and forward items, as well as the URL of the current page.

The easiest way to use these models is to use them in a ListView as illustrated by the following code snippet:

     ListView {
         id: historyItemsList
         anchors.fill: parent
         model: webEngineView.history.items
         delegate:
             Text {
                 color: "black"
                 text: model.title + " - " + model.url + " (" + model.offset + ")"
             }
     }

The ListView shows the content of the corresponding model. The delegate is responsible for the format of the list items. The appearance of each item of the list in the delegate can be defined separately (it is not web engine specific).

The model roles title, url, and icon specify the title, URL, and favicon of the visited page. The offset role specifies the position of the page in respect to the current page (0). A positive number indicates that the page was visited after the current page, whereas a negative number indicates that the page was visited before the current page.

The data models can also be used to create a menu, as illustrated by the following code snippet:

                 Menu {
                     id: historyMenu
                     Instantiator {
                         model: root.currentWebView?.history?.items
                         MenuItem {
                             required property var model
                             text: model.title
                             onTriggered: root.currentWebView.goBackOrForward(model.offset)
                             checkable: !enabled
                             checked: !enabled
                             enabled: model.offset
                         }

                         onObjectAdded: function (index, object) {
                             historyMenu.insertItem(index, object);
                         }
                         onObjectRemoved: function (index, object) {
                             historyMenu.removeItem(object);
                         }
                     }
                 }

For the complete example, see WebEngine Quick Nano Browser.

See also WebEngineHistoryModel.

## Property Documentation

### backItems : WebEngineHistoryModel `[read-only]`

A WebEngineHistoryModel object that you can use to extract information about back items; that is, the pages that were visited before the current page.

See also WebEngineHistoryModel, forwardItems, and items.

### forwardItems : WebEngineHistoryModel `[read-only]`

A WebEngineHistoryModel object that you can use to extract information about forward items; that is, the pages that were visited after the current page.

See also WebEngineHistoryModel, backItems, and items.

### items : WebEngineHistoryModel `[read-only]`

A WebEngineHistoryModel object that you can use to extract information about back items, forward items, and the current item in the history.

See also WebEngineHistoryModel, backItems, and forwardItems.

## Method Documentation

### `[since QtWebEngine 1.11]` void clear()

Clears the history.

This method was introduced in QtWebEngine 1.11.