Setting static path to image source



  • hi friends

    I am trying to set static path to an image source which i was not able to overcome..I do not want an image to be used from qrc file...So i need to access an image from desktop in ubuntu qml qt..here i tried like

    Image {
    id: xxx
    anchors.centerIn: parent.center
    source: "file:///home/xx......../image1.jpg"
    or
    source: "/home/xx......../image1.jpg"
    }

    i could not load that image and i am trying hard to get..it will be greta if some one can help me with this..

    Thanks in Advance friends...


  • Moderators

    Hi,

    I don't see any problem in source of Image element. Use "file:///" as prefix to path.
    Are you sure that the image path is correct ?
    Any error printed to the console ?



  • Hi thanks for reply..

    I have used both methods..i did nt get any errors also..yeah i have given right path..


  • Moderators

    Can you post the complete code ? Please use Code tags "@@" while posting.



  • Hi
    Here is the code posted ..sory i was not knowing how to use code tags

    @
    ListView {

        id : list
        anchors { left: parent.left; top: shutterButton.bottom; right: parent.right; bottom: parent.bottom}
        spacing: 3
        orientation: ListView.Horizontal
        model: 10              
        delegate: Rectangle {
            anchors { verticalCenter: parent.verticalCenter }
            width: 70; height: 70; color: "grey"; border.color: "#000"; radius: 5
            Image {
                id: imagecap
                anchors { centerIn: parent }
                visible: true
                source: "file:///home/bala/Desktop/Image1.jpg"
            }
        }
    }
    

    @


  • Moderators

    Alright Question, Is this the only code in your QML ? It seems you have not given width and height to ListView. Please try again with proper width and height for ListView.
    I'm assuming now that the file path is absolutly correct.



  • Hi,
    No this is nly part of the code...Actual thing is i am capturing an image from camera...where image is saved in sd card...so i have to give that path here...yeah i will try by giving width and height for list view and update u



  • i tried with width and height for list view also but in no vain..did u get that working for u


  • Moderators

    Well i tried this and it worked for me
    @
    ListView {
    id : list
    width: 200
    height: 300
    spacing: 3
    model: 10
    orientation: ListView.Horizontal
    delegate: Rectangle {
    anchors { verticalCenter: parent.verticalCenter }
    width: 70; height: 70;
    color: "grey";
    border.color: "#000";
    radius: 5
    Image {
    id: imagecap
    anchors { centerIn: parent }
    source: "file:///home/user1/Pictures/star.jpg"
    }
    }
    }
    @



  • hi thanks
    i have not checked on desktop till now..it works gud for me on desktop..but it does not work on android mobile


  • Moderators

    On Android it must be a different path.



  • Hi
    Actual code is i am capturing an image and saving that image in one path using "camera" class .I found where the image is saved using "camera.imageCapture.capturedimagepath()" ..path is like "/storage "/sdcard0/DCIM/******etc /img.png"..i assigned the path to listview image source. i deployed the application on android phone and found the path ,bt it is not retrieving in image source in listview...this is exactly my requirement..

    Thanks for guiding...:-)


  • Moderators

    And does it work if you assign some other already existing image ?
    any errors in Qt Creator's console when you run the application on phone ?
    Is the image that you captured a valid image ? you can try opening it in default image viewer on phone



  • yeah i have included images through qrc file but nt static paths...in my phone it does not printt anything on console window...yeah image is an valid one and i am able to open and see in phone..

    image saved in phone at: "/storage/sdcard0/DCIM/Pictures/IMG_00001.jpg"

    the same path i have given as source to image as
    "file:///storage/sdcard0/DCIM/Pictures/IMG_00001.jpg"



  • hi

    I found some bug in the aboe code i have given..
    Inside the delegate->Rectangle image is placed...I could not access that image outside..How do i do that?


  • Moderators

    Is the image accessible outside Rectangle ? You can try to use Image element directly instead of placing inside the Rectangle. But i don't think so that would be a problem.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.