Cannot get QML FolderListModel to work?
-
Hi.
I'm trying to get a list of.xml
files in a folder usingFolderListModel
but when I use
folderModel.rowCount()
, it always returns 0.ApplicationWindow { visible: true FolderListModel { id: folderModel //folder: "qrc:///qml/remotes" folder: "file:///" + applicationDirPath + "/remotes" nameFilters: ["*.xml"] showFiles: true showDirs: false } LauncherList { id: ll anchors.fill: parent Component.onCompleted: { console.debug(folderModel.rowCount()) console.debug(folderModel.folder) } } }
applicationDirPath
is set inmain.cpp
:QQmlApplicationEngine engine; engine.rootContext()->setContextProperty("applicationDirPath", QGuiApplication::applicationDirPath());
The output of
console.debug(folderModel.folder)
shows the correct path, butfolderModel.rowCount()
always returns 0, so I must be doing something wrong? -
Update: The model itself seems to work, only the rowCount() method or count properties don't seem to work?
-
@Diracsbracket
that is most likly the case, becauseFolderListModel
has no function or property calledrowCount
it hascount
count : int Returns the number of items in the current folder that match the filter criteria.
LauncherList
seems to be a custom QML-Item, maby that one hasrowCount
property or function, and you confused them ? -
@J.Hilk
thanks. I got the rowCount() from the Qt Creator's context help, but I agree it may not be usable in QML. Also, no errors are reported when I use it?. However, I also tried to use thecount
property, and that one also always returns 0. The ListView I use to test theFolderListModel
however correctly shows the files.... -
@Diracsbracket mmh, on completed might be the wrong point in time to check the count property, try the following:
FolderListModel { id: folderModel folder: "file:///" + applicationDirPath + "/remotes" nameFilters: ["*.xml"] showFiles: true showDirs: false onCountChanged: console.log("Count Changed",count) }
-
@J.Hilk said in Cannot get QML FolderListModel to work?:
onCountChanged: console.log("Count Changed",count)
OK that works... I'm new to QML and the declarative paradigm and I'm affraid it will take a lot of time to get used to it... and to get even simple things to work.