How to use FolderListModel?



  • I create a QtQuick app and replace the main.qml with the code below. I try to show all files and dirs in my home path in a Mac OS X system. But nothing shows up. Could some one help to figure out what I did wrong? Thanks in advance.

    import QtQuick 2.4
    import QtQuick.Controls 1.3
    import QtQuick.Window 2.2
    import QtQuick.Dialogs 1.2
    import QtQuick.Layouts 1.1
    import Qt.labs.folderlistmodel 2.1
    
    ApplicationWindow {
        visible: true
        title: "Test"
        width: 200
        height: 400
    
        ListView {
            anchors.fill: parent
    
            FolderListModel {
                id: folderModel
                showDirs: true
                showDirsFirst: true
                rootFolder: "file:///Users/enderson"
                nameFilters: ["*.*"]
            }
    
            Component {
                id: fileDelegate
                Text { text: fileName }
            }
    
            model: folderModel
            delegate: fileDelegate
        }
    }
    

    b.t.w.:
    Qt5.5
    .pro:

    TEMPLATE = app
    
    QT += qml quick widgets
    
    SOURCES += main.cpp \
        UiBridge.cpp
    
    RESOURCES += qml.qrc
    
    LIBS += -framework CoreFoundation -framework Foundation
    
    # Additional import path used to resolve QML modules in Qt Creator's code model
    QML_IMPORT_PATH =
    
    # Default rules for deployment.
    include(deployment.pri)
    

Log in to reply
 

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