Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.14.2
-
None
Description
Hi,
QT 5.14 introduced the QWebEnginePage.LifecycleState API. While playing
with this API to try to suspend inactive browser tabs after certain time,
I noticed an issue.
1. Two tabs are created to open example.com.
2. After 2 seconds, one tab's QWebEnginePage is put into QWebEnginePage::LifecycleState::Discarded state
3. Switch to the discarded will change its QWebEnginePage's LifecycleState to QWebEnginePage::LifecycleState::Active.
However the page is completely blank. Web
Inspector shows HTML source was already there and I can even select
an invisible element somewhere on the page to inspect it. If I switch to the other tab and then switch back, the page will be shown.
Here's the full code for the above description (or download the attached .zip file),
1. file.pro
TEMPLATE = app
QT += webenginewidgets
SOURCES += main.cpp
2. main.cpp
#include <QApplication>
#include <QWebEngineView>
#include <QTabWidget>
#include <QWebEnginePage>
#include <QTimer>
QTabWidget *tab_widget_;
QWebEngineView *views_[2];
void current_tab(int i)
{ printf("%d state=%d\n", i, (int)views_[i]->page()->lifecycleState()); }void discard_tab() {
QWebEnginePage *page;
for (int i=0; i<2; i++)
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QUrl qurl = QUrl(QStringLiteral("http://example.com"));
QTabWidget tab_widget;
tab_widget_ = &tab_widget;
QWebEngineView views[2];
for (int i=0; i<2; i++)
// discard tab after
QTimer::singleShot(2000, &discard_tab);
printf("discard=%d\n", (int)QWebEnginePage::LifecycleState::Discarded);
QObject::connect(&tab_widget, &QTabWidget::currentChanged, ¤t_tab);
tab_widget.show();
return app.exec();
}