Cannot get QML FolderListModel to work?
-
Hi.
I'm trying to get a list of.xmlfiles in a folder usingFolderListModelbut 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) } } }applicationDirPathis 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? -
Hi.
I'm trying to get a list of.xmlfiles in a folder usingFolderListModelbut 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) } } }applicationDirPathis 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?
-
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, becauseFolderListModelhas no function or property calledrowCount
it hascountcount : int Returns the number of items in the current folder that match the filter criteria.LauncherListseems to be a custom QML-Item, maby that one hasrowCountproperty or function, and you confused them ? -
@Diracsbracket
that is most likly the case, becauseFolderListModelhas no function or property calledrowCount
it hascountcount : int Returns the number of items in the current folder that match the filter criteria.LauncherListseems to be a custom QML-Item, maby that one hasrowCountproperty 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 thecountproperty, and that one also always returns 0. The ListView I use to test theFolderListModelhowever correctly shows the files.... -
@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 thecountproperty, and that one also always returns 0. The ListView I use to test theFolderListModelhowever 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) } -
@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.