How can I access Python code from JavaScript in PyQT 5.7?
<p>I used to do it by attaching an object</p>

<pre><code>self.page().mainFrame().addToJavaScriptWindowObject("js_interface", self.jsi)
</code></pre>

<p>In 5.7 I do:</p>

<pre><code>self.page().setWebChannel(self.jsi)
</code></pre>

<p>But I understandibly get a JavaScript error when I try to access exposed functions:</p>

<pre><code>js: Uncaught ReferenceError: js_interface is not defined
</code></pre>

<p>Googling around I found that I should use qwebchannel.js, but I couldn't find the file or instructions on how to use it anywhere (there was some info, but only in some examples provided when installing QT, not PyQT).</p>

<p>Take a look at <a href="http://doc.qt.io/qt-5/qtwebchannel-standalone-example.html" rel="nofollow">this page</a>. It contains a useful example (in c++ but easily translatable into python).</p>

<p>First of all, you have to use a websocket to communicate from html to your app and viceversa.</p>

<p>Then you can set up your QWebChannel.</p>

javascript python qt pyqt