Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Add Static Path to Image Source in qml
Forum Update on Monday, May 27th 2025

Add Static Path to Image Source in qml

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 5.4k 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.
  • B Offline
    B Offline
    beemaneni
    wrote on 31 Jul 2014, 08:58 last edited by
    #1

    hi
    I need to add images to Image source statically from Project folder...
    @Image{
    id: imageCap
    anchors.centerIn: parent
    width: parent.width; height: parent.height; smooth: true
    fillMode: Image.PreserveAspectFit
    source: "file:///Images/Image1.png"
    }@

    Here ImageCapture is my project name and i have created Images folder in it and placed few images in it..I dont want to give relative path from my system and as well as i dont want to use qrc file..so that wen i build app i shud be able to load images in all other syatems also...so how do i do that..Can anyone help me on this issue...

    Thanks in Advance...

    Bala B
    Infinite Computer systems
    Chennai

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dheerendra
      Qt Champions 2022
      wrote on 31 Jul 2014, 13:36 last edited by
      #2

      Try with this.

      source : Qt.resolvedUrl("file:///C:/Qt/Images/Image1.png")

      assuming that your files are in C:/Qt/Images directory

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • B Offline
        B Offline
        beemaneni
        wrote on 31 Jul 2014, 14:51 last edited by
        #3

        Hi
        I do not want to give absolute path..I want to give relative path from project folder...Absolute path works fine...Let me tel u my scenary...

        I want to buld app on desktop and run in on Android Os..so i need that relative path...please post ur reply if u knw that..
        thanks in Advance

        Bala B
        Infinite Computer systems
        Chennai

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dheerendra
          Qt Champions 2022
          wrote on 31 Jul 2014, 16:17 last edited by
          #4

          I may not know the exact answer. Let me try.
          Your earlier post said that you don't want to give relative path. Hence absolute path came into picture.

          You can give relative path like the following.

          Image {
              source : "../images/ball.png"
           }
          

          I have kept binary and main.qml in <home>qt/bins directory. Images in <home>/qt/images while executing the program.

          Not sure why u don't want to use resource files.

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply
          0
          • B Offline
            B Offline
            beemaneni
            wrote on 1 Aug 2014, 05:20 last edited by
            #5

            Hi
            sorry that was a mistake from me while typing.I require nly relative path. And the above sample of code does not work for me..
            And the reason y i do not want to use qrc is,i will be capturing images from camera and will be saved in project folder during runtime...So i cant add that files to qrc at dynamic time right..so i chose this method..Do u think is there a better way to handle..?

            Thanks for ur Reply Dheerendra

            Bala B
            Infinite Computer systems
            Chennai

            1 Reply Last reply
            0

            4/5

            31 Jul 2014, 16:17

            • Login

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