IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

Qt for WebAssembly

Runs Qt applications in a secure sandbox in the browser.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

Qt for WebAssembly

WebAssembly is a binary format that allows sand-boxed executable code in web pages. This format is nearly as fast as native machine code, and is now supported by all major web browsers.

Qt for WebAssembly is a platform plugin that lets you build Qt applications, which can be integrated into your web pages. It doesn't require any client-side installations and reduces the server-side resource usage.

Getting Started with Qt for WebAssembly

 

Install 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.

Refer to the emscripten documentation for more information about checking out the Emscripten SDK and installing and activating Emscripten for your Qt version.

After installation, you should have emscripten in your path. Check this with the following command:

 
Sélectionnez
em++ --version

Each minor release of Qt supports a known-good Emscripten version. That Emscripten version will be supported for the lifetime of that Qt version.

The known-good versions are:

  • Qt 5.12: 1.38.16

  • Qt 5.13: 1.38.27 (multithreading: 1.38.30)

  • Qt 5.14: 1.38.27 (multithreading: 1.38.30)

  • Qt 5.15: 1.39.8

Use emsdk to install specific emscripten versions. For example, to install it for Qt 5.13, enter:

  • ./emsdk install sdk-fastcomp-1.38.27-64bit

  • ./emsdk activate sdk-fastcomp-1.38.27-64bit

After installation, you should have emscripten in your path. Check this with the following command:

 
Sélectionnez
em++ --version
Download the binaries

The binary builds can be downloaded in the Downloads section using your Qt account.

Build Qt from the sources

Alternatively, you could download the Qt sources in the Downloads section, and build Qt from it.

Configure Qt as a cross-compile build for the wasm-emscripten platform. This will implicitly set the "-static" and "-no-feature-thread" options. Pass the -compile-examples option to enable examples.

 
Sélectionnez
./configure -xplatform wasm-emscripten -nomake examples -prefix $PWD/qtbase

On Windows, make sure you have MinGW as well as sed in your PATH and configure with the following:

 
Sélectionnez
configure -no-warnings-are-errors -xplatform wasm-emscripten -platform win32-g++ -nomake examples -prefix %CD%\qtbase

Build required modules:

 
Sélectionnez
make module-qtbase module-qtdeclarative [other modules]

The Qt build is a static build, and does not support threads.

Build and run your application
 
Sélectionnez
$ /path/to/qt-wasm/qtbase/bin/qmake
$ make

This generates the following files:

Generated file

Brief Description

app.html

HTML container

qtloader.js

JS API for loading Qt apps

app.js

JS API for loading Qt apps

app.wasm

emscripten app binary

When deploying the app, the compression is typically handled on the server side. We recommend to compress the wasm binaries because this typically reduces the size of the binary by 50 %.

Test-run your application

You can test-run your application in the following way:

 
Sélectionnez
/path/to/emscripten/emrun --browser=firefox appname.html

Some examples

Limitations

The most important limitation is that the Qt build is static, and does not support threads.

For further info, refer to Known_issues_and_platform_notes.

External resources

Licenses

Qt for WebAssembly is available under commercial licenses from The Qt Company. In addition, it is available under the GNU General Public License, version 3. See Qt Licensing for further details.

See Also

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+