WebAssembly - Qt 6.6.0 - Embind
-
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 tomodule
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 toModule
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!
-
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")
.