[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: Re: [PyQt] QWebEnginePage.LifecycleState doesn't work as expected in PyQt while the official C++ lif
From: Coiby Xu <coiby.xu () gmail ! com>
Date: 2020-04-19 4:03:30
Message-ID: 20200419040330.hpfxiwru63gr2atn () r
[Download RAW message or body]
>The only way I can determine if there is a PyQt-specific problem is to
>compare it with a C++ equivalent of the above code that behaves
>differently.
Here is the C++ equivalent code which shows it's not a PyQt-specific
issue,
1. minimal.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++) {
page = views_[i]->page();
page->setLifecycleState(QWebEnginePage::LifecycleState::Discarded);
printf("%d state=%d\n", i, (int)page->lifecycleState());
}
}
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++) {
views_[i] = &views[i];
views[i].setUrl(qurl);
views[i].resize(1024, 750);
tab_widget.addTab(&views[i], "tab1");
}
// 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();
}
FWIW I've reported it to https://bugreports.qt.io/browse/QTWB-49.
Thank you for the reply!
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic