Important: Please read the Qt Code of Conduct -

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: "" // 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: or is there another way to achieve this?

    best regards

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

Log in to reply