Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for WebAssembly
  4. Python Backend/QML Frontend Can I Convert To WebAssembly?

Python Backend/QML Frontend Can I Convert To WebAssembly?

Scheduled Pinned Locked Moved Unsolved Qt for WebAssembly
5 Posts 3 Posters 2.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Edwin F.E Offline
    Edwin F.E Offline
    Edwin F.
    wrote on last edited by Edwin F.
    #1

    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":

    backend.py

    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!

    1 Reply Last reply
    0
    • Edwin F.E Offline
      Edwin F.E Offline
      Edwin F.
      wrote on last edited by
      #2

      Is there anyone out there in the universe?! Anyone?! :)

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • lorn.potterL Offline
          lorn.potterL Offline
          lorn.potter
          wrote on last edited by
          #4

          I am unsure about python webassembly, but googling got me this:
          https://almarklein.org/python_and_webassembly.html

          Freelance Software Engineer, Platform Maintainer QtWebAssembly, Maintainer QtSensors
          Author, Hands-On Mobile and Embedded Development with Qt 5 http://bit.ly/HandsOnMobileEmbedded

          1 Reply Last reply
          0
          • Edwin F.E Offline
            Edwin F.E Offline
            Edwin F.
            wrote on last edited by Edwin F.
            #5

            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.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved