Skip to content

Fix WASM QT 6.9#7341

Merged
waruqi merged 13 commits intoxmake-io:devfrom
luadebug:em
Feb 25, 2026
Merged

Fix WASM QT 6.9#7341
waruqi merged 13 commits intoxmake-io:devfrom
luadebug:em

Conversation

@luadebug
Copy link
Member

@luadebug luadebug commented Feb 23, 2026

Resolves: #7340
Resolves: #7050

Test project stuff:
wasmrun.zip

Currently my approach requires to uncomment stuff. Although it looks like that stuff should be injected by XMake itself.

❯ cat ~/wasmrun/src/main.cpp 
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QtPlugin>

// #ifdef Q_OS_WASM
// Q_IMPORT_PLUGIN(QWasmIntegrationPlugin)
// #endif

int main(int argc, char *argv[])
{
// #ifdef Q_OS_WASM
//     Q_INIT_RESOURCE(wasmwindow);
//     Q_INIT_RESOURCE(wasmfonts);
// #endif

    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;
    const QUrl url(u"qrc:/qt/qml/qt_app/Main.qml"_qs);
    QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed,
        &app, []() { QCoreApplication::exit(-1); },
        Qt::QueuedConnection);
    engine.load(url);

    return app.exec();
}

Aw I need really some good idea on how to fix/improve this.

find ~/wasmrun -name "static_import.cpp" | xargs cat
#include <QtPlugin>
Q_IMPORT_PLUGIN(QtQuickControls2BasicStyleImplPlugin)
Q_IMPORT_PLUGIN(QtQmlModelsPlugin)
Q_IMPORT_PLUGIN(QtQuick_WindowPlugin)
Q_IMPORT_PLUGIN(QtQmlPlugin)
Q_IMPORT_PLUGIN(QtQuickControls2BasicStylePlugin)
Q_IMPORT_PLUGIN(QtQuickControls2Plugin)
Q_IMPORT_PLUGIN(QtQuickLayoutsPlugin)
Q_IMPORT_PLUGIN(QtQuickControls2ImplPlugin)
Q_IMPORT_PLUGIN(QtQuickTemplates2Plugin)
Q_IMPORT_PLUGIN(QtQmlWorkerScriptPlugin)
Q_IMPORT_PLUGIN(QtQuick2Plugin)
Q_IMPORT_PLUGIN(QWasmIntegrationPlugin)
int init_qt_plugin_resources() {
    Q_INIT_RESOURCE(wasmwindow);
    Q_INIT_RESOURCE(wasmfonts);
    return 0;
}
static int s_init_qt_plugin_resources = init_qt_plugin_resources();

After last commit we get next to expected result without JavaScript flooding errors:

image

But the problem is now to optimize existing PR content, so yeah... help wanted be like.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @luadebug, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the build process and runtime compatibility for Qt applications targeting WebAssembly (WASM) using Xmake. It introduces optimizations for static plugin imports, updates Emscripten compiler flags to align with modern Qt 6.0+ requirements, and implements dynamic patching for generated HTML and JavaScript files to resolve common WASM-specific issues and enhance preload file support.

Highlights

  • Qt WASM Build Optimization: Optimized the generation of static_import.cpp for Qt plugins to prevent unnecessary file writes, improving build efficiency.
  • Emscripten Flag Updates: Enhanced Emscripten linker and shell flags for Qt 6.0+ WebAssembly (WASM) targets, including adjustments to exception handling, exported runtime methods, and exported functions for better compatibility and functionality.
  • Dynamic HTML and JavaScript Patching for WASM: Improved Qt WASM application deployment by dynamically patching wasm_shell.html and the generated JavaScript file to support preload files, address 'use strict' issues, and fix visualViewport access.
  • Static Plugin Loading for WASM: Enabled static plugin loading for Qt widget and quick applications when building for WebAssembly platforms, ensuring proper plugin integration.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • xmake/rules/qt/load.lua
    • Optimized the generation of static_import.cpp to only write the file if its content has changed, reducing redundant disk I/O.
    • Updated Emscripten ldflags and shflags for Qt 6.0+ WASM builds, specifically changing DISABLE_EXCEPTION_CATCHING=1 to ASSERTIONS=0.
    • Expanded the list of EXPORTED_RUNTIME_METHODS to include FS, callMain, cwrap, ccall, setValue, getValue, UTF8ToString, and stringToUTF8 for Qt 6.0+ WASM.
    • Added _main, _malloc, and _free to EXPORTED_FUNCTIONS for Qt 6.0+ WASM builds.
  • xmake/rules/qt/xmake.lua
    • Added logic to patch wasm_shell.html for Qt 6.0+ WASM builds, including support for preloadfiles and patching containerElements and qtContainerElements.
    • Modified the generated .js file for Qt 6.0+ WASM to remove 'use strict'; directives to prevent runtime issues.
    • Implemented a patch for this.visualViewport access in the generated .js file to handle undefined this context.
    • Integrated static plugin configuration into qt.widgetapp and qt.quickapp rules when targeting WASM platforms, passing relevant plugins to the load function.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@luadebug luadebug marked this pull request as draft February 23, 2026 15:03
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces several improvements and fixes for Qt builds, particularly for the WebAssembly (Wasm) platform. The changes include optimizing file generation to avoid unnecessary writes, adding and updating Emscripten flags for newer Qt versions, and patching generated HTML and JavaScript files to fix compatibility issues. My review focuses on improving code maintainability by reducing duplication and suggesting structural improvements. Overall, these are valuable changes for enhancing Wasm support.

@luadebug luadebug changed the title Em Fix WASM QT 6.9 Feb 23, 2026
@luadebug luadebug marked this pull request as ready for review February 23, 2026 22:42
@luadebug
Copy link
Member Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request introduces necessary updates for Qt 6.9 WASM support, including static plugin resource initialization and essential patches for the Emscripten glue code. These changes address issues with selector handling and memory growth. I've suggested some improvements regarding the Emscripten flags and the efficiency of the file patching process.

@luadebug luadebug requested a review from waruqi February 25, 2026 03:25
i = i + 1
end
if content:sub(i, i) == ";" then i = i + 1 end
local new_func = "var findCanvasEventTarget = target => {\n"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if there will be compatibility issues with this hard-coded JS code in Qt WASM.

Copy link
Member Author

@luadebug luadebug Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我总是愿意等待,也许会有更好的选择出现。目前没有这个功能,它无法加载我在.zip 文件中提交的 QtQuick 应用。

@waruqi waruqi merged commit 27f49cd into xmake-io:dev Feb 25, 2026
35 of 37 checks passed
@waruqi waruqi added this to the v3.0.8 milestone Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants