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


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

Log in to reply

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