Enumerate/print all QRC resource from QML
-
Hi,
I would like to print (for debug purpose) all available QRC elements from QML.
For C++ there's widely availableQDirIterator it(":", QDirIterator::Subdirectories); while (it.hasNext()) { qDebug() << it.next(); }
I found this code snippet to use from QML
FolderListModel { id: folderModel folder: "qrc:/" nameFilters: ["*"] onCountChanged: { console.log("=> QRC Model content changed to %1 elements".arg( folderModel.count)) for (var i = 0; i < folderModel.count; i++) { console.log("=> %1".arg(folderModel.get(i, "filePath"))) } } }
Unfortunately, above solutions prints only TOP level folders in QRC (according to folder value). It doesn't recursively print content.
And I would like to see this.
How to do it?
PS: I can useGammaRay
which will show this and it's acceptable solution (as a external GUI tool). Yet, still code solution is most welcome. -
Make a model (or just a QStringList) in c++ and expose it to QML.
-
FolderListModel.isFolder() can be used to build a list of all subfolders to traverse.
eg:FolderListModel { id: folderModel folder: "file:///path/to/root" property var folders: [] property var files: [] onFolderChanged: { for (var i = 0; i < folderModel.count; i++) { var filePath = "file://" + folderModel.get(i, "filePath"); if (folderModel.isFolder(i)) folders.push(filePath); else files.push(filePath); } if (folders.length) folderModel.folder = folders.pop(); else console.log("All files:", folderModel.files); } }
This works for a file: url. I suspect it will with a qrc, but have not verified.
-
Thank you all for your feedback.
I just want to test if all QRC elements were loaded properly and their paths are built correctly.
At current project we use 100% QML and there's no place for me to expose C++ (or it would take too much time for debug purpose).
GammaRay is good enough at the moment.