有QWebPage::saveFrameStateRequested信号:
此信号在框架中导航页面的历史记录更改之前不久发出,例如在历史记录中导航时。
您可以使用它来跟踪历史更改:
void MainWindow::saveFrameStateRequested(QWebFrame *frame, QWebHistoryItem *item) {
// this slot is executed before the history is changed,
// so we need to wait a bit:
QTimer::singleShot(100, this, SLOT(listHistoryItems()));
}
void MainWindow::listHistoryItems() {
for (QWebHistoryItem historyItem: view->page()->history()->items()) {
qDebug() << "item" << historyItem.url() << historyItem.title();
}
}
void MainWindow::finishLoading(bool) {
// (re)connect the signal to track history change,
// maybe there is a better place to connect this signal
// where disconnect won't be needed
disconnect(view->page(), SIGNAL(saveFrameStateRequested(QWebFrame*,QWebHistoryItem*)),
this, SLOT(saveFrameStateRequested(QWebFrame*,QWebHistoryItem*)));
connect(view->page(), SIGNAL(saveFrameStateRequested(QWebFrame*,QWebHistoryItem*)),
this, SLOT(saveFrameStateRequested(QWebFrame*,QWebHistoryItem*)));
}
修改后的Fancy Browser示例截图。