Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Enumerate/print all QRC resource from QML
Forum Updated to NodeBB v4.3 + New Features

Enumerate/print all QRC resource from QML

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 3 Posters 645 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sebastian Mosiej
    wrote on last edited by Sebastian Mosiej
    #1

    Hi,
    I would like to print (for debug purpose) all available QRC elements from QML.
    For C++ there's widely available

     QDirIterator 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 use GammaRay which will show this and it's acceptable solution (as a external GUI tool). Yet, still code solution is most welcome.

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Make a model (or just a QStringList) in c++ and expose it to QML.

      (Z(:^

      1 Reply Last reply
      0
      • jeremy_kJ Offline
        jeremy_kJ Offline
        jeremy_k
        wrote on last edited by
        #3

        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.

        Asking a question about code? http://eel.is/iso-c++/testcase/

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Sebastian Mosiej
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved