QWebEngineHistory Class
QWebEngineHistory 类表示网络引擎页面的历史。更多
Header: | #include <QWebEngineHistory> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS WebEngineCore) target_link_libraries(mytarget PRIVATE Qt6::WebEngineCore) |
qmake: | QT += webenginecore |
在 QML 中: | WebEngineHistory |
继承: | QObject |
公共函数
void | back() |
QWebEngineHistoryItem | backItem() const |
QList<QWebEngineHistoryItem> | backItems(int maxItems) const |
QWebEngineHistoryModel * | backItemsModel() const |
bool | canGoBack() const |
bool | canGoForward() const |
void | clear() |
int | count() const |
QWebEngineHistoryItem | currentItem() const |
int | currentItemIndex() const |
void | forward() |
QWebEngineHistoryItem | forwardItem() const |
QList<QWebEngineHistoryItem> | forwardItems(int maxItems) const |
QWebEngineHistoryModel * | forwardItemsModel() const |
void | goToItem(const QWebEngineHistoryItem &item) |
QWebEngineHistoryItem | itemAt(int i) const |
QList<QWebEngineHistoryItem> | items() const |
QWebEngineHistoryModel * | itemsModel() const |
相关非成员
QDataStream & | operator<<(QDataStream &stream, const QWebEngineHistory &history) |
QDataStream & | operator>>(QDataStream &stream, QWebEngineHistory &history) |
详细描述
每个网络引擎页面都包含一个已访问页面的历史记录,可通过QWebEnginePage::history() 访问。
历史记录使用当前项的概念,将访问过的页面分为可通过使用back() 和forward() 函数前后导航访问的页面。当前项目可以通过调用currentItem() 获得,历史记录中的任意项目也可以通过传入goToItem() 变为当前项目。
通过调用backItems() 函数,可以获得描述通过返回可以访问的页面的项目列表;同样,通过forwardItems() 函数,可以获得描述当前页面前面的页面的项目列表。使用items() 函数可获得项目总列表。
此外,还提供了以下QWebEngineHistoryModel 数据模型对象:
backItemsModel()
, 包含已访问页面的 URL。forwardItemsModel()
, 包含访问当前页面后访问过的页面的 URL。itemsModel()
包含后退和前进项目的 URL 以及当前页面的 URL。
与容器一样,我们也提供了以列表形式检查历史记录的功能。历史记录中的任意项目可通过itemAt() 函数获取,项目总数可通过count() 函数给出,历史记录可通过clear() 函数清除。
QWebEngineHistory 的状态可以使用 >> 操作符保存到QDataStream ,也可以使用 << 操作符加载。
另请参阅 QWebEngineHistoryItem 和QWebEnginePage 。
成员函数文档
void QWebEngineHistory::back()
将当前项目设置为历史记录中的前一个项目,并转到相应页面;即返回一个历史项目。
QWebEngineHistoryItem QWebEngineHistory::backItem() const
返回历史记录中当前项目之前的项目。
QList<QWebEngineHistoryItem> QWebEngineHistory::backItems(int maxItems) const
返回后退历史记录列表中的项目列表。最多返回maxItems 条目。
另请参阅 forwardItems()。
QWebEngineHistoryModel *QWebEngineHistory::backItemsModel() const
返回表示访问页面 URL 的数据模型。
注: 属性backItems 的获取函数。
bool QWebEngineHistory::canGoBack() const
如果历史记录中当前项目之前有项目,则返回true
;否则返回false
。
另请参阅 canGoForward() 。
bool QWebEngineHistory::canGoForward() const
如果有项目要转到,则返回true
;否则返回false
。
另请参阅 canGoBack() 。
[invokable]
void QWebEngineHistory::clear()
清除历史记录。
注: 可通过元对象系统和 QML 调用此函数。参见Q_INVOKABLE 。
int QWebEngineHistory::count() const
返回历史记录中的项目总数。
QWebEngineHistoryItem QWebEngineHistory::currentItem() const
返回历史记录中的当前项目。
int QWebEngineHistory::currentItemIndex() const
返回历史记录中当前项目的索引。
void QWebEngineHistory::forward()
将当前项目设置为历史记录中的下一个项目,并转到相应页面;即向前移动一个历史项目。
QWebEngineHistoryItem QWebEngineHistory::forwardItem() const
返回历史记录中当前项目之后的项目。
QList<QWebEngineHistoryItem> QWebEngineHistory::forwardItems(int maxItems) const
返回前向历史记录列表中的条目列表。最多返回maxItems 条目。
另请参阅 backItems()。
QWebEngineHistoryModel *QWebEngineHistory::forwardItemsModel() const
返回数据模型,该数据模型表示访问当前页面后所访问页面的 URL。
注: 属性forwardItems 的获取函数。
void QWebEngineHistory::goToItem(const QWebEngineHistoryItem &item)
将当前项目设置为历史记录中指定的item ,并转到该页面。
QWebEngineHistoryItem QWebEngineHistory::itemAt(int i) const
返回历史记录中索引i 处的项目。
QList<QWebEngineHistoryItem> QWebEngineHistory::items() const
返回当前历史记录中所有项目的列表。
QWebEngineHistoryModel *QWebEngineHistory::itemsModel() const
返回数据模型,该数据模型表示历史记录中的后退项目、前移项目和当前项目的 URL。
注: 属性items 的获取函数。
相关非成员
QDataStream &operator<<(QDataStream &stream, const QWebEngineHistory &history)
将网络引擎历史记录history 保存到stream 中。
QDataStream &operator>>(QDataStream &stream, QWebEngineHistory &history)
将stream 中的网络引擎历史记录加载到history 中。
© 2025 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.