我创建了一个QtQuick应用程序,并使用下面的代码替换main.qml。我尝试在Mac OS X系统中显示我家路径中的所有文件和目录。但没有任何表现。有人可以帮助弄清楚我做错了什么吗?提前谢谢。
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)
答案 0 :(得分:6)
我发现了问题。使用rootFolder是错误的。使用'文件夹'如下属性
folder: "file:///Users/enderson"