如何使用 FolderListModel [英] How to use FolderListModel
本文介绍了如何使用 FolderListModel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个 QtQuick 应用程序并将 main.qml 替换为下面的代码.我尝试在 Mac OS X 系统的主路径中显示所有文件和目录.但什么也没有出现.我怎样才能弄清楚我做错了什么?
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. How can I figure out what I did wrong?
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
}
}
顺便说一句:Qt5.5和 .pro 文件:
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)
推荐答案
我发现了问题.使用 rootFolder 是错误的.使用文件夹"属性,如下所示
I found the problem. Using rootFolder is wrong. Use 'folder' property like below
folder: "file:///Users/enderson"
这篇关于如何使用 FolderListModel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文