Tag Archives: QWebEngineView

Pyqt5: How to solve the uncaught referenceerror when Python uses qwebengineview

problem

In the previous example in which Python used ecarts to draw charts in pyqt5, the radar was successfully loaded using qwebengineview, but an error was reported when the rising sun Sunburst was loaded later:

js:Uncaught ReferenceError: setData is not defined

After querying the data, we know that the custom SetData method cannot be found because the web page is not fully loaded.

Solution:

Call after the page is fully loaded.

sunburst_view.load(QUrl("file:///sunburst.html"))
sunburst_view.loadFinished.connect(set_sunburst_data)  # 加上这一句
sunburst_layout.addWidget(sunburst_view)

def set_sunburst_data(self):
    js = "setData({0})".format(self.data)
    self.hero_count_view.page().runJavaScript(js)

solve the problem.