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



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

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

然后 Python 崩溃

视窗 10 64 位 蟒蛇 3.72(32 位( PyQt5 4.19.18

谷歌搜索了一个看到的人报告问题(有时是C++(,但没有明确指示该怎么做。

非常简单的情况:

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

在某些时候,我在另一个管理通知的类中使用 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__":块中。

相关内容

最新更新