Qt for WebAssembly

WebAssembly 是允许在网页沙盒执行代码的二进制格式。这种格式几乎和本机代码一样快,且现在所有主流 Web 浏览器都支持。

Qt for WebAssembly 是 平台插件 ,允许构建可以被集成到网页的 Qt 应用程序。它不需要安装任何客户端,并减少服务器端资源的使用率。

Qt for WebAssembly 快速入门

安装 Emscripten

emscripten is a toolchain for compiling to asm.js and Webassembly. It lets you run Qt on the web at near-native speed without plugins.

参考 Emscripten 文档编制 for the installation procedure.

安装后,路径下应该有 Emscripten。采用以下命令校验这:

em++ --version
					

构建 Qt 从源

Download the Qt 5.12 sources and build Qt from source. Specify that we are cross-compiling for wasm 使用 emscripten :

$ ~/Qt/5.12.0/Src/configure -xplatform wasm-emscripten -nomake examples -prefix $PWD/qtbase
$ make module-qtbase module-qtdeclarative [other modules]
					

Qt 构建是静态构建,且不支持线程。

Build your application

$ /path/to/qt-wasm/qtbase/bin/qmake
$ make
					

这生成下列文件:

生成的文件 简要描述
app.html HTML 容器
qtloader.js 用于加载 Qt APP 的 JS API
app.js 用于加载 Qt APP 的 JS API
app.wasm 二进制 Emscripten APP

当部署 APP 时,通常在服务器侧处理压缩。我们推荐压缩 wasm 二进制,因为这通常会将二进制尺寸减少 50%。

一些范例

局限性

最重要的局限性是 Qt 构建是静态的,且不支持线程。

了解进一步信息,参考 Known_issues_and_platform_notes .

外部资源

许可

Qt for WebAssembly 在商业许可下是可用的来自 Qt 公司 。此外,它是可用的根据 GNU GPL (一般公共许可) 第 3 版 。见 Qt 许可 进一步了解细节。

另请参阅 WebAssembly 资源站点 , Qt for WebAssembly 快速入门 , and Remote UIs with WegGL and WebAssemblhy.