Problems with Open-Source Downloads read https://www.qt.io/blog/problem-with-open-source-downloads and https://forum.qt.io/post/638946

relative path to external resource



  • Hi there :D

    I am playing around with Qt for WebAssembly and was wondering, how to use assets from a relative path from the compiled warm if deployed on a server?

    Assuming I use some images in my application, I would normally embed them in my qrc resource file,
    but for WA the compiled binary is already really large, so I thought I could load the images directly from the hosting server, is this possible?

    Image {
        //source: "../../assets/BG.jpg" // local, using embedded resource from arc file
        //source: "file:///assets/BG.jpg" // local, absolute path -> works for desktop build
        //source: "http://my.server.com/BG.jpg" // online absolute path -> works for WA build, although I have to pay respect to the protocol (http or https), also difficult because of CORS if deployed on another server
        source: "file:/BG.jpg" // online relative path how to?
    }
    

    trying to load an image from a relative path throws me an error:

    QML Image: Cannot open: file:///BG.jpg
    

    Do I have to map my relative path to an absolute like in this post: https://forum.qt.io/topic/76590/relative-path-to-absolute-path or is there another way to achieve this?

    best regards
    SyntaX



  • @SyntaX You would need to preload the files at compile time.

    https://emscripten.org/docs/tools_reference/emcc.html#emcc-preload-file


Log in to reply