summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/wasm/qtloader.js
diff options
context:
space:
mode:
authorMorten Sørvig <morten.sorvig@qt.io>2023-06-08 13:53:48 +0200
committerMorten Sørvig <morten.sorvig@qt.io>2023-07-04 15:42:01 +0200
commitd659c93068120474fb433ad55c619c5d52ab7d8d (patch)
tree5849b0cd089a5f645cb18a8465a058a23c560aed /src/plugins/platforms/wasm/qtloader.js
parent3f8f79ddafc68e2a3e1bdf59355e9a4958f46d12 (diff)
wasm: add "qtdir" qtloader config property
This points to the location where qtloader should find the Qt installation when loading Qt shared libraries and plugins. The path is relative to the path of the html file which contains the application, and is set to "qt" by default. Deployment of the Qt installation to the web server is left to the app developer, since this depends on the exact use case. One possible way to deploy is to create a "qt" symlink to the Qt installation, for instance: html/myapp/myapp.html html/myapp/myapp.wasm html/myapp/qt -> /path/to/qt Pick-to: 6.6 Task-number: QTBUG-63925 Change-Id: I76b129dffc75c06ff6bc67d8c20ce12557b32f31 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Diffstat (limited to 'src/plugins/platforms/wasm/qtloader.js')
-rw-r--r--src/plugins/platforms/wasm/qtloader.js16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/plugins/platforms/wasm/qtloader.js b/src/plugins/platforms/wasm/qtloader.js
index 1d1e7fb6d1..4ce27de6a5 100644
--- a/src/plugins/platforms/wasm/qtloader.js
+++ b/src/plugins/platforms/wasm/qtloader.js
@@ -24,6 +24,11 @@
* - module: Promise<WebAssembly.Module>
* The module to create the instance from (optional). Specifying the module allows optimizing
* use cases where several instances are created from a single WebAssembly source.
+ * - qtdir: string
+ * Path to Qt installation. This path will be used for loading Qt shared libraries and plugins.
+ * The path is set to 'qt' by default, and is relative to the path of the web page's html file.
+ * This property is not in use when static linking is used, since this build mode includes all
+ * libraries and plugins in the wasm file.
*
* @return Promise<instance: EmscriptenModule>
* The promise is resolved when the module has been instantiated and its main function has been
@@ -51,6 +56,8 @@ async function qtLoad(config)
if (typeof config.qt.entryFunction !== 'function')
throw new Error('config.qt.entryFunction is required, expected a function');
+ config.qt.qtdir ??= 'qt';
+
config.qtContainerElements = config.qt.containerElements;
delete config.qt.containerElements;
config.qtFontDpi = config.qt.fontDpi;
@@ -88,6 +95,15 @@ async function qtLoad(config)
config.onRuntimeInitialized = () => config.qt.onLoaded?.();
+ const originalLocateFile = config.locateFile;
+ config.locateFile = filename =>
+ {
+ const originalLocatedFilename = originalLocateFile ? originalLocateFile(filename) : filename;
+ if (originalLocatedFilename.startsWith('libQt6'))
+ return `${config.qt.qtdir}/lib/${originalLocatedFilename}`;
+ return originalLocatedFilename;
+ }
+
// This is needed for errors which occur right after resolving the instance promise but
// before exiting the function (i.e. on call to main before stack unwinding).
let loadTimeException = undefined;