Search code examples
c++qtwebassemblyqfiledialog

Access local user file on Qt for Web Assembly


I want to access to local files (read binary file) in my software on Qt for Web assembly.

It seems there is already a function to do that: QFileDialog::getOpenFileContent. But I can't find any related example to show how to use this function. I'll appreciate that if someone help me how to use this function.

Thanks.


Solution

  • Since Qt WebAssembly runs in the same javascript sandbox, it does not have easy access to the local filesystem, which is why we came up with a way to have access, which is getOpenFileContent.

    You could possibly use the private API which is used by getOpenFileContent, which is in src/gui/platform/wasm/qwasmlocalfileaccess_p.h See 790cf25f9d811f2cda7e252b4f1844e8fce27e2a

    Both of these will open a file dialog.

    You can also sync the file up to the sandbox yourself using Emscripten's filesytem API first, and then you will be able to access it as if were local to the application. https://emscripten.org/docs/api_reference/Filesystem-API.html