Python Backend/QML Frontend Can I Convert To WebAssembly?
-
I have only seen examples converting C++ Qt apps to WebAssembly using EMscripten. I have not seen anything converting Qt apps with a Python 'backend' to WebAssembly...
Are there any examples out there? Any tools available for this? For example an app like so with the following:
QML frontend:
main.qml
import QtQuick 2.12 import QtQuick.Window 2.2 import QtQuick.Controls 2.3 ApplicationWindow { id: window visible: true width: Screen.width height: Screen.height color: "white" Button { anchors.centerIn: parent onClicked: { backend.hi_from_qml('Nombre') } } }
And a Python "backend":
from PySide2.QtCore import Qt, QObject, Signal, Slot, QCoreApplication from PySide2.QtWidgets import QApplication from PySide2.QtQml import QQmlApplicationEngine import sys class Backend(QObject): def __init__(self): QObject.__init__(self) @Slot(str) def hi_from_qml(self, name): print(f'Hi from qml: {name}') if __name__ == '__main__': app = QApplication(sys.argv) engine = QQmlApplicationEngine() ctx = engine.rootContext() backend = Backend() ctx.setContextProperty("backend", backend) engine.load('main.qml') if not engine.rootObjects(): sys.exit(-1) sys.exit(app.exec_())
One starts up the app like so from the terminal:
Ed-MacBook-Air:test$ python3 backend.py Hi from qml: Nombre
How would I convert this QML/Python app to Webassembly to serve through the browser? Any help would be greatly appreciated, I've been looking everywhere.
A possible but unfortunate workaround I'm thinking about in case this is not possible...Use PyBind11 as a thin 'C++ layer' between my existing QML frontend and my Python backend. And then compile that with EMscripten and be able to serve that, would that work?
Thanks!
-
Hi,
Yes there is. Qt for WASM being pretty new, you will have to be more patient because there's currently likely not a lot of people using it here.
As for your question, I would say currently no.
This stack overflow answer will likely be of interest with regard to Python and WASM.
-
I am unsure about python webassembly, but googling got me this:
https://almarklein.org/python_and_webassembly.html -
Thanks guys @SGaist and @lorn-potter
It seems like it is not really supported at this time and I will have to look into the alternative of putting a layer between the QML and Python backend in C++, essentially becomes a C++ app, but I only want to use C++ as a pass through to the Python somehow using PyBind11...I will try to see if that will work.