How to clear or delete Image in QML



  • Hello.
    How to clear or delete Image in QML?

    I'd like to make the application.
    it likes "slide show" application.

    example

    Image {
        id: mPicture
    }
    Timer {
        interval: 2000
        running: true
        repeat: true
        property var fList //it has many imagefile path ex. aaa.png, bbb.png...
        property int nextIdx
        onTriggered:{
            mPicture.source = "file://" + fList[nextIdx]
            nextIdx++
            if(fList.length <= nextIdx) {
                nextIdx = 0
            }
        }
    }
    

    It's working.
    but few minutes later application will down.
    I think I have to clear or delete mPicture.source.

    I already try it.

        mPicture.source = ""
        mPicture.source = "file://" + fList[nextIdx]
    

    But it's same.

    Could you let me know how should I do?
    thanks.



  • @nishiokas most likly you indexing fList wrong and outrun the length.

    However I would suggest taking a look the the SlideShow-Example from the docs.

    That should help you more.



  • @J-Hilk
    Thanks for reply.
    I'm sorry I didn't take more information.
    "fList" has many image file.
    and the application is working.

    I would not big change to the application.
    I'd like to know how to clear image.

    Thanks for your help!



  • Simply updating the mPicture.source should be sufficient to release any resources consumed by the previously displayed image; there's no need for any additional code to explicitly "clear" it.

    What's the exact nature of "application will down"? Do you get an error message on the console? If it's a crash, where does a stack-trace say it crashes?


Log in to reply
 

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