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?
Forum Updated to NodeBB v4.3 + New Features

How to do callbacks/slots in Qt for WebAssembly?

Scheduled Pinned Locked Moved Solved Qt for WebAssembly
7 Posts 3 Posters 1.2k Views 2 Watching
  • 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.
  • E Offline
    E Offline
    Edwin F.
    wrote on 10 Nov 2020, 23:04 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

    J 1 Reply Last reply 11 Nov 2020, 09:05
    0
    • E Edwin F.
      10 Nov 2020, 23:04

      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

      J Offline
      J Offline
      JonB
      wrote on 11 Nov 2020, 09:05 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?

      E 1 Reply Last reply 11 Nov 2020, 15:37
      0
      • J JonB
        11 Nov 2020, 09:05

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

        E Offline
        E Offline
        Edwin F.
        wrote on 11 Nov 2020, 15:37 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?

        J 1 Reply Last reply 11 Nov 2020, 15:42
        0
        • E Edwin F.
          11 Nov 2020, 15:37

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

          J Offline
          J Offline
          JonB
          wrote on 11 Nov 2020, 15:42 last edited by JonB 11 Nov 2020, 15:42
          #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
          • L Offline
            L Offline
            lorn.potter
            wrote on 11 Nov 2020, 19:50 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

            E 1 Reply Last reply 12 Nov 2020, 13:55
            3
            • L lorn.potter
              11 Nov 2020, 19:50

              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.

              E Offline
              E Offline
              Edwin F.
              wrote on 12 Nov 2020, 13:55 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

              L 1 Reply Last reply 12 Nov 2020, 20:51
              0
              • E Edwin F.
                12 Nov 2020, 13:55

                @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

                L Offline
                L Offline
                lorn.potter
                wrote on 12 Nov 2020, 20:51 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

                4/7

                11 Nov 2020, 15:42

                • Login

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