Qt WebAssembly Platform Notes
WebAssembly (or webasm) is a bytecode format intended to be executed in a virtual machine inside a web browser. This allows an application to be deployed to a device with a compliant web browser without going through any installation steps. The application will run inside a secure sandbox in the web browser. This makes it appropriate for applications that do not need full access to the device capabilities, but benefits from a swift and uncomplicated installation process.
Supported target browsers and devices
桌面
-
Chrome
-
FireFox
-
Safari
-
Edge(Chrome)
If the browser supports WebAssembly, then Qt should run.
注意:
Qt 有固定 WebGL 要求,也适用于不直接使用 WebGL 的 APP。浏览器经常把旧的/不支持的 GPU 列入 WebGL 黑名单。
移动
-
Android 浏览器
-
Mobile Safari
注意:
There is currently no support for text input using the virtual keyboard. Safari currently does not support wasm modules of the size Qt produces.
Qt does not make direct use of operating system features and it makes no difference if, for example, FireFox runs on Windows or macOS. Qt does use some operating system adaptations, for example for ctrl/cmd key handling on macOS.
已知问题
参考
wiki
.
已知局限性
-
Debugging: Qt debug and logging output is printed on the JavaScript console, which can be accessed via browser "Developer Tools" or similar.
-
Nested event loops are not supported. Applications should not call, for example,
QDialog::exec
() or create a new
QEventLoop
对象。
-
Qt renders application content to a canvas element, and does not use (other) native DOM elements. This means accessibility (screen readers) are not supported and that text inputs won't trigger virtual keyboards.
-
WebGL is required, even for applications which do not use OpenGL themselves. Most modern browsers support WebGL, but note that some browsers blacklist certain older GPUs. The Qt loader will detect this and display an error message.
-
Child OpenGL windows are not supported. The window compositor (in the Qt for Wasm platform plugin) supports raster windows only.
-
Qt will detect OpenGL support as OpenGL ES. In reality the browser will be providing WebGL. WebGL is based on ES and is very similar, but there are some incompatibilities. See WebGL and OpenGL Differences.
-
Applications do not have access to system fonts. Font files must be distributed with the application, for example in Qt resources. Qt for WebAssembly itself embeds one such font.
-
High-DPI and scaling: High-DPI rendering is supported, and so is setting the overall UI visual size using the browser zoom feature. Browser font size (and type) settings have no effect on Qt applications.
-
There may be artifacts of uninitialized graphics memory on some Qt Quick Controls 2 components, such as checkboxes.
-
Network access: the web sandbox limits network access to a subset of what is available for native apps.
-
QNetworkAccessManager
http requests to the web page origin server, or to a server which supports CORS.
-
QWebScoket connections to any host.
-
TCP and UDP socked tunneling using over WebSockets using a websockify server [implemented by Emscripten, not tested].
-
Websockify v0.8.0 can be used to tunnel TCP connections with QT5.12 but it is MANDATORY to specify the base64 or binary subprotocols before calling
QWebSocket::open
().
-
例如:
QWebSocket
socket;
QUrl
url{
QString
("ws://server:port")};
QNetworkRequest
request{url};
request.setRawHeader("Sec-WebSocket-Protocol", "binary");
socket.open(request);
-
Link-time warnings of the form: "cannot represent a NaN literal '0x7fdae4bde910' with custom bit pattern", are expected.
-
Expected footprint (download size): Wasm modules as produced by the compiler can be large, but compress well.
Compression is typically handled on the web server side, using standard compression features: the server compresses automatically or picks up pre-compressed versions of the files. There's generally no need to have special handling of wasm files.