Details
-
Bug
-
Resolution: Invalid
-
P4: Low
-
None
-
5.6.2, 5.7.1, 5.8.0, 5.9.0
-
None
Description
The application hangs on QEventLoop and the QWebEnginePage doesn't emit any signals.
This happens when exposed object's slot has been invoked from JavaScript:
main.cpp
#include <QApplication> #include <QDebug> #include <QTimer> #include <QWebEnginePage> #include <QWebChannel> class CppBrother: public QObject { Q_OBJECT public: CppBrother():QObject(){} Q_INVOKABLE void openAnotherPage(){ QWebEnginePage page; qDebug()<<"loading another page"; page.setHtml("<p>hello</p>"); QEventLoop loop; connect(&page, &QWebEnginePage::loadFinished, &loop, &QEventLoop::quit); loop.exec(); // hangs when called from javascript qDebug()<<"another page load finished"; emit finished(); } signals: void finished(); }; int main(int argc, char *argv[]) { QApplication app(argc, argv); CppBrother cppBrother; cppBrother.openAnotherPage(); //not hanging here QWebChannel chan; chan.registerObject("cppbrother", &cppBrother); QWebEnginePage page; page.setWebChannel(&chan); page.load(QUrl("qrc:///page.xhtml")); QObject::connect(&cppBrother, &CppBrother::finished, qApp, &QApplication::quit); int ret = app.exec(); qDebug()<<"page finished"; return ret; } #include "main.moc"
page.xhtml
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta content="application/xhtml+xml; charset=UTF-8" http-equiv="Content-Type"/> <script src="qrc:///qtwebchannel/qwebchannel.js"></script> <script> window.onload = function(){ console.warn("window.onload") new QWebChannel(qt.webChannelTransport, function(channel) { console.warn("transport ready") channel.objects.cppbrother.openAnotherPage() console.warn("after openAnotherPage") }) } </script> </head> </html>