Qt for WebAssembly 开发的网页,在 iOS 设备上打开会提示:Out of memory
如图:
解决办法:
环境:Qt 6.7.0 + WebAssembly multi-threaded + Emscripten Compiler 3.1.50
在CMakeLists.txt 中增加:
set_target_properties(untitled3 PROPERTIES QT_WASM_INITIAL_MEMORY "150MB")
set_target_properties(untitled3 PROPERTIES QT_WASM_MAXIMUM_MEMORY "350MB")
后面的内存大小数值自行按需调整即可。
注意这个 QT_WASM_MAXIMUM_MEMORY 只有 6.7.0 以后版本才有
Qt官方解释:
Link time error such as "wasm-ld: error: initial memory too small", requires adjustment of the initial memory size. Use QT_WASM_INITIAL_MEMORY to set the initial size in kb, which must be a multiple of 64KB (65536). Default is 50 MB. In CMakeLists.txt: set_target_properties(<target> PROPERTIES QT_WASM_INITIAL_MEMORY "150MB")
Runtime error such as "RangeError: Out of memory" can be worked around by setting MAXIMUM_MEMORY to a value the device supports, for example target_link_options(<your target> PRIVATE -s MAXIMUM_MEMORY=1GB)