Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-138132

It is recommended to add a recursive interface for QRC files.

XMLWordPrintable

    • Icon: Suggestion Suggestion
    • Resolution: Unresolved
    • Icon: Not Evaluated Not Evaluated
    • None
    • 6.10.0
    • Core: Resource System
    • None
    • All

      After adding resources in the qt_add_qml_module function in Qt6, the resource path is not clear and it is not possible to directly copy the resource path. It is recommended to add an interface for traversing the qrc files to facilitate debugging. Reference code is as follows:

      QStringList getAllFilesRecursively(const QString& dirPath,
                                         const QStringList& nameFilters = QStringList())
      {
          QStringList fileList;
          QDir dir(dirPath);    if (!dir.exists()) {
              qWarning() << "Directory does not exist:" << dirPath;
              return fileList;
          }  
          dir.setFilter(QDir::Files | QDir::NoDotAndDotDot);
          if (!nameFilters.isEmpty()) {
              dir.setNameFilters(nameFilters);
          }    
          const auto files = dir.entryList();
          for (const QString& file : files) {
              fileList.append(dir.absoluteFilePath(file));
          }    
          dir.setFilter(QDir::AllDirs | QDir::NoDotAndDotDot);
          const auto subdirs = dir.entryList();
          for (const QString& subdir : subdirs) {
              fileList.append(getAllFilesRecursively(dir.absoluteFilePath(subdir), nameFilters));
          }    return fileList;
      }
      int main(int argc, char *argv[])
      {
          QGuiApplication app(argc, argv);    
          const QStringList prefixes = {"qrc:/", ":/"};
          for (const QString& prefix : prefixes) {
              qDebug().noquote() << "Files under " << prefix << ":";
              foreach (const QString& file, getAllFilesRecursively(prefix)) {
                  qDebug().noquote() << "  " << file;
              }
          }
      ...

       

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            hjk hjk
            junchong.tang Junchong Tang
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes