How to refresh FolderListModel?



  • hello everybody,

    Is there any way to refresh the FolderListModel so the view is able to display the new files added.

    Thank you



  • You mean when files are added in the folder, then the FolderListModel should automatically update the model?

    Or manually refresh the FolderListModel?



  • there is no deference I need the view to feel that something is added, whether this done manually or automatically.



  • I know this is an old thread but I searched for a long time to find an answer to this. The following worked for me, without this, when a file was added/deleted the list view was not updated properly (unless I exited and reopened the application).

    @import QtQuick 1.1
    import Qt.labs.folderlistmodel 1.0

    ListView {
    id: view
    model: folderModel
    delegate: Text { text: fileName }

    property variant folderModel
    function updateModel() {
        var folder = ""
        if (folderModel) {
            folder = folderModel.folder
            folderModel.destroy()
        }
        folderModel = modelComponent.createObject(view, {"folder": folder})
    }
    
    Component {
        id: modelComponent
        FolderListModel {}
    }
    
    Component.onCompleted: updateModel()
    

    }
    @
    Source from:
    http://stackoverflow.com/questions/11359854/update-listview-showin-in-tab-bar-layout-qml



  • Looks like FolderListModel update the list automatically once new files are added or remove from path:(Qt5.7.1)

            ListView
            {
                id:myListViewUSB
                anchors.fill: parent
    
                FolderListModel
                {
                    id: folderModelUSB
                    folder: "file:///mnt/usb"
                }
                model: folderModelUSB
    
                delegate:
                Text
                {
                    text:  fileName
                    anchors.horizontalCenter: parent.horizontalCenter
                }
            }

Log in to reply
 

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