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. How to do callbacks/slots in Qt for WebAssembly?

How to do callbacks/slots in Qt for WebAssembly?

Scheduled Pinned Locked Moved Solved Qt for WebAssembly
7 Posts 3 Posters 1.2k 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
    #1

    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

    JonBJ 1 Reply Last reply
    0
    • Edwin F.E Edwin F.

      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

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @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?

      Edwin F.E 1 Reply Last reply
      0
      • JonBJ JonB

        @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?

        Edwin F.E Offline
        Edwin F.E Offline
        Edwin F.
        wrote on last edited by
        #3

        @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?

        JonBJ 1 Reply Last reply
        0
        • Edwin F.E Edwin F.

          @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?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @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.

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

            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.

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

            Edwin F.E 1 Reply Last reply
            3
            • lorn.potterL lorn.potter

              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.

              Edwin F.E Offline
              Edwin F.E Offline
              Edwin F.
              wrote on last edited by
              #6

              @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

              lorn.potterL 1 Reply Last reply
              0
              • Edwin F.E Edwin F.

                @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

                lorn.potterL Offline
                lorn.potterL Offline
                lorn.potter
                wrote on last edited by
                #7

                @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

                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
                1

                • Login

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