Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for WebAssembly
  4. relative path to external resource
Forum Updated to NodeBB v4.3 + New Features

relative path to external resource

Scheduled Pinned Locked Moved Unsolved Qt for WebAssembly
2 Posts 2 Posters 700 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SyntaXS Offline
    SyntaXS Offline
    SyntaX
    wrote on last edited by SyntaX
    #1

    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

    lorn.potterL 1 Reply Last reply
    0
    • SyntaXS SyntaX

      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

      lorn.potterL Offline
      lorn.potterL Offline
      lorn.potter
      wrote on last edited by
      #2

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

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

      Freelance Software Engineer, Platform Maintainer QtWebAssembly, Maintainer QtSensors
      Author, Hands-On Mobile and Embedded Development with Qt 5 http://bit.ly/HandsOnMobileEmbedded

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved