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 * 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 * 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;