How to use FolderListModel

人走茶凉 提交于 2019-12-10 19:04:32

问题


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 and .pro file:

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)

回答1:


I found the problem. Using rootFolder is wrong. Use 'folder' property like below

folder: "file:///Users/enderson"


来源:https://stackoverflow.com/questions/31736997/how-to-use-folderlistmodel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!