Important: Please read the Qt Code of Conduct -

Add Static Path to Image Source in qml

  • hi
    I need to add images to Image source statically from Project folder...
    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 that wen i build app i shud be able to load images in all other syatems how do i do that..Can anyone help me on this issue...

    Thanks in Advance...

  • Qt Champions 2017

    Try with this.

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

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

  • 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 i need that relative path...please post ur reply if u knw that..
    thanks in Advance

  • Qt Champions 2017

    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.

  • 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 i chose this method..Do u think is there a better way to handle..?

    Thanks for ur Reply Dheerendra

Log in to reply