Hi,
I am having problem getting a simple implementation of QWebChannel between python and QWebEngineView working, what am I missing here (I posted the same over at the Qt forums but the traffic there seems very low)?
import sys
from PySide6.QtCore import QObject
from PySide6.QtWebChannel import QWebChannel
from PySide6.QtWebEngineWidgets import QWebEngineView
from PySide6.QtWidgets import QApplication
class Py(QObject):
def msg(self, msg):
print("msg: ", msg)
if __name__ == "__main__":
app = QApplication(sys.argv)
web = QWebEngineView()
channel = QWebChannel(web)
py = Py(app)
channel.registerObject("py", py)
web.page().setWebChannel(channel)
web.setHtml('''
<html>
<head>
<script type="text/javascript" src="qrc:///qtwebchannel/qwebchannel.js"></script>
<script>
var py
channel = new QWebChannel(qt.webChannelTransport, function(channel) {
py = channel.objects.py
})
</script>
</head>
<body>
Demo<br>
<button onclick="py.msg('button clicked')">click me</button>
</body>
</html>
''')
web.show()
app.exec()
```
Cheers