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. WebAssembly - Qt 6.6.0 - Embind

WebAssembly - Qt 6.6.0 - Embind

Scheduled Pinned Locked Moved Unsolved Qt for WebAssembly
2 Posts 1 Posters 622 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.
  • J Offline
    J Offline
    just_a_developer
    wrote on last edited by just_a_developer
    #1

    Hello,

    I compiled my app for WebAssembly with Qt 6.4.1 so far.

    My embedding website is sending messages to the Qt app via a Javascript interface which is registered in C++ this way :

    #ifdef EMSCRIPTEN
    
    #include <emscripten/bind.h>
    
    EMSCRIPTEN_BINDINGS(javascriptPublicInterface)
    {
    	emscripten::class_<JavascriptPublicInterface>("JavascriptPublicInterface")
    		.function("myProperty", &JavascriptPublicInterface::myPropertyEMS)
    		.function("setMyProperty", &JavascriptPublicInterface::setMyPropertyEMS);
    	emscripten::function("self", &JavascriptPublicInterface::self, emscripten::allow_raw_pointers());
    }
    
    #endif
    

    So my embedding website could call :

    module.self().setMyProperty("something")
    

    Now I am working on updating my app to be built using Qt 6.6.0 .
    As far as I understand the app compiles, and it is running, but I don't have access to module any more (it's undefined).

    Using the web browser's Javascript debugger, I can see, that this function in myapp.js is running, and it receives an unwind exception :

    function callMain(args = []) {
      assert(runDependencies == 0, 'cannot call main when async dependencies remain! (listen on Module["onRuntimeInitialized"])');
      assert(__ATPRERUN__.length == 0, 'cannot call main when preRun functions remain to be called');
    
      var entryFunction = _main;
    
      args.unshift(thisProgram);
    
      var argc = args.length;
      var argv = stackAlloc((argc + 1) * 4);
      var argv_ptr = argv >> 2;
      args.forEach((arg) => {
        HEAP32[argv_ptr++] = stringToUTF8OnStack(arg);
      });
      HEAP32[argv_ptr] = 0;
    
      try {
    
        var ret = entryFunction(argc, argv);
    
        // if we're not running an evented main loop, it's time to exit
        exitJS(ret, /* implicit = */ true);
        return ret;
      }
      catch (e) {
        return handleException(e);
      }
    }
    

    When the breakpoint in the exception handler is hit, I can access to Module (with upper case first letter) from the Javascript console. As soon as I let the debugger continue, I don't have access to Module any more, but the app seems to continue running.

    How could I get the access back to my Javascript public interface?

    Thank you four your help in advance!

    1 Reply Last reply
    1
    • J Offline
      J Offline
      just_a_developer
      wrote on last edited by
      #2

      I realized that I can easily get access to my JavascriptPublicInterface again, by slightly modifying the generated myapp.html :
      so from :

              async function init()
              {
                  const spinner = document.querySelector('#qtspinner');
                  const screen = document.querySelector('#screen');
                  const status = document.querySelector('#qtstatus');
      
                  const showUi = (ui) => {
                      [spinner, screen].forEach(element => element.style.display = 'none');
                      if (screen === ui)
                          screen.style.position = 'default';
                      ui.style.display = 'block';
                  }
      
                  try {
                      showUi(spinner);
                      status.innerHTML = 'Loading...';
      
                      const instance = await qtLoad({
      

      I updated to :

              var instance = null 
              async function init()
              {
                  const spinner = document.querySelector('#qtspinner');
                  const screen = document.querySelector('#screen');
                  const status = document.querySelector('#qtstatus');
      
                  const showUi = (ui) => {
                      [spinner, screen].forEach(element => element.style.display = 'none');
                      if (screen === ui)
                          screen.style.position = 'default';
                      ui.style.display = 'block';
                  }
      
                  try {
                      showUi(spinner);
                      status.innerHTML = 'Loading...';
      
                      instance = await qtLoad({
      

      so now I can call instance.self().setMyProperty("something") .

      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