[Solved] Read File name from folderlistmodel



  • In List View i have stored n number of files.How to read File name from folderlistmodel based on index..Here i know the value of index.up on clicking on listview i need to find out respective filename based on index. i found get method in folderListModel but of no use...Can any one help me out where i am going wrong r is there really a way to finout filename
    @FolderListModel{
    id: folderList
    folder: imagePath
    nameFilters: ["*.png"]
    }
    MouseArea {
    anchors.fill: parent
    property var valuex
    onClicked: {
    xxx.text = folderList.get(index,"fileName")
    }
    @

    Thanks in Advance



  • Try this.
    @
    ListView {
    id : view
    ....
    ....
    ....

    MouseArea {
    anchors.fill: parent
    onClicked: {
    console.log(" I am here"+currentIndex)
    console.log(" My name is ="+view.model.get(currentIndex,"fileName"))
    }
    }
    }
    @



  • Hi Dheerendra..
    Thanks for reply..
    That doesnt work...



  • ListView has property called currentIndex. It works based on that. Here is complete example I tried on 3 platforms.

    @ListView {
    id : view
    width: 200; height: 400

    FolderListModel {
        id: folderModel
        nameFilters: ["*.qml"]
    }
    
    Component {
        id: fileDelegate
        Text { text: fileName }
    }
    
    model: folderModel
    delegate: fileDelegate
        MouseArea {
            anchors.fill: parent
            onClicked: {
                console.log(" I am here"+currentIndex)
                console.log(" I am ok ="+view.model.get(currentIndex,"fileName"))
            }
        }
    

    }
    @



  • Hi
    Thanks dheerendra..It works fine...but it does not work with currentIndex..It works with index.

    And i found one more working.Here is the code..
    @ MouseArea {
    anchors.fill: parent
    onClicked: {
    xxx.text = folderList.folder + fileName
    }
    }@

    Thanks
    Bala Beemaneni



  • Good that it solved your issue. As side note, 'index' is visible inside the delegate. 'CurrentIndex' is inside the ListView. Since your mouseArea is inside the delegate, you need to use 'index' only. If your mouseArea is inside the View, you need to use 'currentIndex'.



  • Thanks Dheerendra..Thanks for ur help :-)

    Reagrds
    Bala Beemaneni



  • Why do i get error "TypeError: Result of expression 'songView.model.get' [undefined] is not a function" when i use

    @view.model.get(index,"fileName")@

    Beemaneni.Can you please advice how you get the file name using code below.I get the file name but it also include the whole path leading to the files and the filename change when i just scrolling listview without selecting it.

    @xxx.text = folderList.folder + fileName@



  • try with this
    @ view.model.get(currentIndex,"fileName")@

    If u dont mind post ur code ,let me have a look at that

    Thanks
    Bala Beemaneni



  • Here the simplified code.Anyway i manage to solve.Kind of dirty but at least it work.The code is below.Just make sure only call it when necessary else when scrolling lisview, the file name keep changing even when just scrolling without selecting it.Takes me almost a week to figure it out.Thanks.

    //WORKING CODE
    @
    View.currentItem.DataModel.fileName
    @

    //SAMPLE CODE
    @
    ListView {
    id: View
    clip: true
    model: ListModelling
    delegate: listcomponent
    }
    FolderListModel {
    id: ListModelling
    folder: "file:/accounts/1000/shared"
    //folder: "file"
    showDirs: true
    }
    ListModel {
    id: ListModel
    ListElement {
    folder: ""
    index: 0
    }
    }

     Component {
       id: listcomponent
       ListItem {
           id: listitem
           property variant DataModel: model
           Text { 
              id: showname
               text: fileName
               anchors.verticalCenter: parent.verticalCenter
               anchors.left: foldersymbol.right
               anchors.leftMargin: 10
               anchors.right: parent.right
             }
         }
     }
    

    @


Log in to reply
 

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