diff --git a/src/corelib/kernel/qeventdispatcher_wasm.cpp b/src/corelib/kernel/qeventdispatcher_wasm.cpp index f5c2802aa6f..c0d753c594f 100644 --- a/src/corelib/kernel/qeventdispatcher_wasm.cpp +++ b/src/corelib/kernel/qeventdispatcher_wasm.cpp @@ -567,16 +567,20 @@ void QEventDispatcherWasm::callProcessTimers(void *context) } #if QT_CONFIG(thread) -// Runs a function on the main thread -void QEventDispatcherWasm::runOnMainThread(std::function fn) -{ - static auto trampoline = [](void *context) { + +namespace { + void trampoline(void *context) { std::function *fn = reinterpret_cast *>(context); (*fn)(); delete fn; - }; + } +} + +// Runs a function on the main thread +void QEventDispatcherWasm::runOnMainThread(std::function fn) +{ void *context = new std::function(fn); - emscripten_async_run_in_main_runtime_thread_(EM_FUNC_SIG_VI, reinterpret_cast(&trampoline), context); + emscripten_async_run_in_main_runtime_thread_(EM_FUNC_SIG_VI, reinterpret_cast(trampoline), context); } #endif