WebAssembly 是允許在網頁沙盒執行代碼的二進製格式。這種格式幾乎和本機代碼一樣快,且現在所有主流 Web 瀏覽器都支持。
Qt for WebAssembly 是 平颱插件 ,允許構建可以被集成到網頁的 Qt 應用程序。它不需要安裝任何客戶端,並減少服務器端資源的使用率。
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
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 構建是靜態構建,且不支持綫程。
$ /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.