Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to do callbacks/slots in Qt for WebAssembly?



  • I have a working example of a QML/C++ app compiled to WebAssembly using Emscripten. I realized now after playing with it the C++ code is getting executed on the client machine, not on the server.

    How would the server send a callback to that app, or in other words call a slot on the client app?

    For example the client in a browser gets the html and is using the Qt app in the browser. Then some time later something changes in the db and I want the server to notify the client browser somehow... How is this done, a callback or slot from the server to the client?

    I made an illustration to aide my question. Thanks guys!

    callback.png



  • @Edwin-F
    Before you go any further: do you have anything about the database working in your current WA? I thought server databases are not supported at all in WA? Unless you are managing that yourself, somehow?



  • @JonB The server will have other routes opened up for the client (the Qt app in the browser) to get the data. The server will handle the task of interacting with the db on the same server machine.

    For example if the client gets the Qt app through:

    http://example.com/myapp.html

    In the app there will be URLs baked into the code so that lets say the user logs in by clicking a button, that request will go to the same server on a different endpoint like:

    http://example.com/login

    and the server will interact with the DB...

    So how would I send something from the server back to the client at some point? Websockets?



  • @Edwin-F said in How to do callbacks/slots in Qt for WebAssembly?:

    So how would I send something from the server back to the client at some point? Websockets?

    That would be my thought, because your can't do it over plain HTTP (so far as I am aware; unless you are prepared to poll from client). But I have no experience, so I will stay silent now, and hope someone knowledgable responds to you.



  • Indeed, websockets are your friend. QtWebSockets works with WebAssembly, or you can use the javascript WebSocket API yourself. Caveat being that Qt WebAssembly can be client only - no server support.



  • @lorn-potter Cool thanks for your reply, so you mean the server can send something to the client but not the client to the server, right? I think this question is solved. Thanks guys



  • @Edwin-F WebSockets are two way communication, but only a client process can run on WebAssembly/browser.
    https://doc.qt.io/qt-5/qtwebsockets-index.html


Log in to reply