3

When my Python 3.x apps exists, I get a message on the console

Release of profile requested but WebEnginePage still not deleted. Expect troubles !

and then python crashes

Windows 10 64 bit Python 3.72 (32 bits) PyQt5 4.19.18

Googled around an seen people reporting the problem (sometimes in C++), but not clear indication of what to do.

pretty simple case:

class PmApplication(QMainWindow):
(...) 
     summary=QWebEngineView(self)
(...)
     tabWidget.addTab(summary,"Summary")

and at some point, I generate an HTML document with mako in another class that manages notifications (so, self.web points to summary)

    data.trip = con.execute(sql).fetchall()
    html = self.template.render(d=data)
    self.web.setHtml(html)
    self.web.show()

This works fine until I close the application

I use PyDev, and while ran inside eclipse, I just see alert dialog from Python telling it crashed.

From the command line, I get

Release of profile requested but WebEnginePage still not deleted. Expect troubles !

and then the same dialog from Python

any pointer ? (also, new to python and PyQt5)

thanks

As suggested (and as I should have done), here's a minimal snippet that reproduces the problem

from PyQt5.QtWebEngine import QtWebEngine
from PyQt5 import QtCore,QtWidgets
from PyQt5.QtWidgets import QMainWindow,QWidget
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtWebEngineWidgets import QWebEngineSettings
from PyQt5.Qt import QHBoxLayout
import sys

def main():
    app = QtWidgets.QApplication(sys.argv)
    pm = QMainWindow()
    centralWidget = QWidget(pm)  
    summary=QWebEngineView(pm)
    box = QHBoxLayout()
    box.addWidget(summary)
    centralWidget.setLayout(box)
    html = "<html><head><title>Here goes</title></head><body> Does this work ?</body></html>"
    summary.setHtml(html)
    pm.show()
    sys.exit( app.exec_() )


if __name__ == "__main__":
    main()

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Eric Boisvert
  • 135
  • 3
  • 9

1 Answers1

2

It seems that the problem is caused by creating and executing the QApplication object from within a function. One way to fix the problem is to do something like.

def main(app):
    pm = QMainWindow()
    centralWidget = QWidget(pm)
    summary=QWebEngineView(pm)
    box = QHBoxLayout()
    box.addWidget(summary)
    centralWidget.setLayout(box)
    pm.setCentralWidget(centralWidget)
    html = "<html><head><title>Here goes</title></head><body> Does this work ?</body></html>"
    summary.setHtml(html)
    pm.show()
    app.exec()

if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    main(app)

Alternatively you could move the code in main() directly into the if __name__ == "__main__": block.

Heike
  • 24,102
  • 2
  • 31
  • 45