当 PyQt5 应用程序退出时,我得到 "Release of profile requested but WebEnginePage still not deleted. Expect troubles !"

I get "Release of profile requested but WebEnginePage still not deleted. Expect troubles !" when PyQt5 application exits

当我的 Python 3.x 应用程序存在时,我在控制台上收到一条消息

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

然后 python 崩溃

Windows 10 64 位 Python 3.72(32 位) PyQt5 4.19.18

用 Google 搜索了一个报告问题的人(有时在 C++ 中),但没有明确指示要做什么。

非常简单的案例:

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

并且在某些时候,我在另一个管理通知的 class 中生成了一个带有 mako 的 HTML 文档(因此,self.web 指向摘要)

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

在我关闭应用程序之前,它工作正常

我使用 PyDev,当 运行 在 eclipse 中时,我只看到来自 Python 的警告对话框告诉它崩溃了。

从命令行,我得到

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

然后是 Python

中的相同对话框

任何指针? (另外,python 和 PyQt5 的新手)

谢谢

按照建议(我应该这样做),这里有一个重现问题的最小片段

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()

问题似乎是由在函数内创建和执行 QApplication 对象引起的。解决此问题的一种方法是执行类似的操作。

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)

或者您可以将 main() 中的代码直接移动到 if __name__ == "__main__": 块中。