Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Design Tooling
  3. Qt Design Studio
  4. Relative Paths for Images
Forum Updated to NodeBB v4.3 + New Features

Relative Paths for Images

Scheduled Pinned Locked Moved Solved Qt Design Studio
4 Posts 2 Posters 1.0k Views
  • 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.
  • D Offline
    D Offline
    danilo_jn
    wrote on last edited by
    #1

    Hi everyone, I am quite new to Qt and I'm struggling a bit at the moment. I am using Qt Design Studio to build my application but also doing some light coding. I have managed to import my project into Qt Creator and build a working exe file. Now, I would like to have a folder right next to my exe where I keep my footage so that in case that I want to update said footage I can simply overwrite the file without having to rebuild. I was able to get this working with an absolute path but when I try using a relative path the images get embeded into the exe. This is an example of the paths that I am using:

    ListModel {
    id: pathModel

        ListElement {
            source: "../footage/thumbnails/ducks_thumbnail.jpg"
            isVideo: true
        }
        ListElement {
            source: "../footage/thumbnails/tea_thumbnail.jpg"
            isVideo: true
        }        
        ListElement {
            source: "../footage/thumbnails/ducks_thumbnail.jpg"
            isVideo: false
        }
        ListElement {
            source: "../footage/thumbnails/steam_thumbnail.jpg"
            isVideo: true
        }
        ListElement {
            source: "../footage/thumbnails/girl_talking_thumbnail.jpg"
            isVideo: true
        }
    }
    

    Thanks in advance!

    jsulmJ 1 Reply Last reply
    0
    • D danilo_jn

      Hi everyone, I am quite new to Qt and I'm struggling a bit at the moment. I am using Qt Design Studio to build my application but also doing some light coding. I have managed to import my project into Qt Creator and build a working exe file. Now, I would like to have a folder right next to my exe where I keep my footage so that in case that I want to update said footage I can simply overwrite the file without having to rebuild. I was able to get this working with an absolute path but when I try using a relative path the images get embeded into the exe. This is an example of the paths that I am using:

      ListModel {
      id: pathModel

          ListElement {
              source: "../footage/thumbnails/ducks_thumbnail.jpg"
              isVideo: true
          }
          ListElement {
              source: "../footage/thumbnails/tea_thumbnail.jpg"
              isVideo: true
          }        
          ListElement {
              source: "../footage/thumbnails/ducks_thumbnail.jpg"
              isVideo: false
          }
          ListElement {
              source: "../footage/thumbnails/steam_thumbnail.jpg"
              isVideo: true
          }
          ListElement {
              source: "../footage/thumbnails/girl_talking_thumbnail.jpg"
              isVideo: true
          }
      }
      

      Thanks in advance!

      jsulmJ Online
      jsulmJ Online
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @danilo_jn said in Relative Paths for Images:

      but when I try using a relative path the images get embeded into the exe

      I don't get it: how should this happen? Or do you use a resource file?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      D 1 Reply Last reply
      0
      • jsulmJ jsulm

        @danilo_jn said in Relative Paths for Images:

        but when I try using a relative path the images get embeded into the exe

        I don't get it: how should this happen? Or do you use a resource file?

        D Offline
        D Offline
        danilo_jn
        wrote on last edited by danilo_jn
        #3

        @jsulm So as far as I can tell a resource file is automatically generated either when I export the CMake build files or when I open the CMakeLists file in Qt Creator. I did not write one myself. This is how it looks:

        <RCC>
        <qresource prefix="/qt/qml/content/">
        <file alias="App.qml">C:/QtProjects/Meiningen_Gesellschaft/content/App.qml</file>
        <file alias="Screen01.ui.qml">C:/QtProjects/Meiningen_Gesellschaft/content/Screen01.ui.qml</file>
        <file alias="components/ContentCarousel.qml">C:/QtProjects/Meiningen_Gesellschaft/content/components/ContentCarousel.qml</file>
        <file alias="components/UpdateTimer.qml">C:/QtProjects/Meiningen_Gesellschaft/content/components/UpdateTimer.qml</file>
        <file alias="components/VideoContainer.qml">C:/QtProjects/Meiningen_Gesellschaft/content/components/VideoContainer.qml</file>
        <file alias="footage/ducks.mp4">C:/QtProjects/Meiningen_Gesellschaft/content/footage/ducks.mp4</file>
        <file alias="footage/girl_talking.mp4">C:/QtProjects/Meiningen_Gesellschaft/content/footage/girl_talking.mp4</file>
        <file alias="footage/steam.mp4">C:/QtProjects/Meiningen_Gesellschaft/content/footage/steam.mp4</file>
        <file alias="footage/tea.mp4">C:/QtProjects/Meiningen_Gesellschaft/content/footage/tea.mp4</file>
        <file alias="footage/thumbnails/ducks_thumbnail.jpg">C:/QtProjects/Meiningen_Gesellschaft/content/footage/thumbnails/ducks_thumbnail.jpg</file>
        <file alias="footage/thumbnails/girl_talking_thumbnail.jpg">C:/QtProjects/Meiningen_Gesellschaft/content/footage/thumbnails/girl_talking_thumbnail.jpg</file>
        <file alias="footage/thumbnails/steam_thumbnail.jpg">C:/QtProjects/Meiningen_Gesellschaft/content/footage/thumbnails/steam_thumbnail.jpg</file>
        <file alias="footage/thumbnails/tea_thumbnail.jpg">C:/QtProjects/Meiningen_Gesellschaft/content/footage/thumbnails/tea_thumbnail.jpg</file>
        </qresource>
        </RCC>

        My Custom components and also my footage is listed as an alias and then given a full path. I have also tried the exe on another computer by just adding the required dll files and no footage. The footage was still present so I'm assuming its embeded. Just for my understanding if I have a path like the one on my post ex "../footage/image.jpg" the footage folder would have to be one folder prior to the exe right?

        Thanks again for your time.

        Edit: just as some extra infor the .qrc file is located in my build folder under "build/content/.rcc/content_raw_qml_0.qrc"

        D 1 Reply Last reply
        0
        • D danilo_jn

          @jsulm So as far as I can tell a resource file is automatically generated either when I export the CMake build files or when I open the CMakeLists file in Qt Creator. I did not write one myself. This is how it looks:

          <RCC>
          <qresource prefix="/qt/qml/content/">
          <file alias="App.qml">C:/QtProjects/Meiningen_Gesellschaft/content/App.qml</file>
          <file alias="Screen01.ui.qml">C:/QtProjects/Meiningen_Gesellschaft/content/Screen01.ui.qml</file>
          <file alias="components/ContentCarousel.qml">C:/QtProjects/Meiningen_Gesellschaft/content/components/ContentCarousel.qml</file>
          <file alias="components/UpdateTimer.qml">C:/QtProjects/Meiningen_Gesellschaft/content/components/UpdateTimer.qml</file>
          <file alias="components/VideoContainer.qml">C:/QtProjects/Meiningen_Gesellschaft/content/components/VideoContainer.qml</file>
          <file alias="footage/ducks.mp4">C:/QtProjects/Meiningen_Gesellschaft/content/footage/ducks.mp4</file>
          <file alias="footage/girl_talking.mp4">C:/QtProjects/Meiningen_Gesellschaft/content/footage/girl_talking.mp4</file>
          <file alias="footage/steam.mp4">C:/QtProjects/Meiningen_Gesellschaft/content/footage/steam.mp4</file>
          <file alias="footage/tea.mp4">C:/QtProjects/Meiningen_Gesellschaft/content/footage/tea.mp4</file>
          <file alias="footage/thumbnails/ducks_thumbnail.jpg">C:/QtProjects/Meiningen_Gesellschaft/content/footage/thumbnails/ducks_thumbnail.jpg</file>
          <file alias="footage/thumbnails/girl_talking_thumbnail.jpg">C:/QtProjects/Meiningen_Gesellschaft/content/footage/thumbnails/girl_talking_thumbnail.jpg</file>
          <file alias="footage/thumbnails/steam_thumbnail.jpg">C:/QtProjects/Meiningen_Gesellschaft/content/footage/thumbnails/steam_thumbnail.jpg</file>
          <file alias="footage/thumbnails/tea_thumbnail.jpg">C:/QtProjects/Meiningen_Gesellschaft/content/footage/thumbnails/tea_thumbnail.jpg</file>
          </qresource>
          </RCC>

          My Custom components and also my footage is listed as an alias and then given a full path. I have also tried the exe on another computer by just adding the required dll files and no footage. The footage was still present so I'm assuming its embeded. Just for my understanding if I have a path like the one on my post ex "../footage/image.jpg" the footage folder would have to be one folder prior to the exe right?

          Thanks again for your time.

          Edit: just as some extra infor the .qrc file is located in my build folder under "build/content/.rcc/content_raw_qml_0.qrc"

          D Offline
          D Offline
          danilo_jn
          wrote on last edited by
          #4

          @danilo_jn if anyone is wondering, the right way to do this is:

          source: "file:footage/image.png"

          For it to work with QtDesign Studio simply create a folder called "footage" in the root of your project. Then when you build your app transfer that folder so it's right next to you exe.

          1 Reply Last reply
          0
          • D danilo_jn has marked this topic as solved on

          • Login

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