Opening File Dialog crashes App using Qt for web assembly and emsdk with upstream backend

  • Hi everyone,

    I already asked this from here

    Following the whole install process described here (thanks Lorn), I successully managed to get things to build fast...

    I'm currently trying to access my local files from my application, as I saw it can be done using (cf "Slate" example, which I can build from QtCreator).

    import Qt.labs.platform 1.0 as Platform
    Platform.FileDialog {
            id: openProjectDialog
            objectName: "openProjectDialog"
            nameFilters: ["All files (*)", "JSON files (*.json)"]
            defaultSuffix: "json"

    But I can't access my file/folder system, same when I build the Slate app. Both app crash, and the mozilla firefox console gives me this:
    Screen Shot 2019-10-28 at 16.41.39.png

    When I build simply the Qt source without the upstream backend (following Qt for web assembly wiki), even though it takes almost 15minutes to build and link, I manage to access my files from the browser with the Slate app.

    (But my custom app only gives me this with the qt wiki build, but that's another post... or a quick answer, up to you ;) )
    Screen Shot 2019-10-28 at 16.45.28.png

    My config:

    Qt 5.13.1
    latest emsdk with upstream 1.39.0
    macOS X Sierra 10.12.6
    XCode clang :
    Apple LLVM version 8.0.0 (clang-800.0.42.1)
    Target: x86_64-apple-darwin16.7.0
    Thread model: posix
    InstalledDir: /Applications/

    The wasm-emscripten works fine during the Qt sources build, as it builds beautifully with em++/emcc.

    Is it my setup limitation (llvm 8.00 ) ? I thought you didn't have to an up-to-date (or custom-built) version of llvm with the upstream build...

    Thank you all.

  • Having the same Problem here.
    Could never access my own filesys. Theres got to be a solution to avoid the sandbox.

  • Hello @kuersat , which problem ? Does it crash when you try to open a dialog with same config as me ?

    Or do you have the same "lame" display in the dialog as shown in my post ?

  • What you want is QFileDialog::getOpenFileContent

    All other QFileDialog functions will only access the sandbox filesystem.

    Also you need to use this fork of slate:

  • @lorn-potter

    Thanks for the answer. I can now access my files but QFile can't open the json files I'm looking to process.

    When using the getOpenFilenContent, I have this in the web browser console:

    RuntimeError: unreachable executed qtloader.js line 270 > WebAssembly.compile:10489242:1

    There is something I don't understand. Why could I build the Slate example, open files with the Qt Labs FileDialog and use QFile API, but now that I use emscripten I just can't... pretty frustrating.

    Is there a work around to QFile to be able to parse/use local files in the browser ?

    Thanks a lot.

  • @DamienL
    QFileDialog::getOpenFileContent is the workaround for accessing system/local files due to the javascript sandbox that webassembly lives in.

Log in to reply