Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QDirIterator repeating Dir
Qt 6.11 is out! See what's new in the release blog

QDirIterator repeating Dir

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 4.9k Views 1 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.
  • D Offline
    D Offline
    Dredvard
    wrote on last edited by
    #1

    I'm trying to iterate through all the directories in a file structure. However I'm finding that QDirIterator is repeating, and I'm not sure why.

    @
    QString root = "/accounts/1000/";
    QDirIterator it(root, QDir::Dirs | QDir::NoDot | QDir::NoSymLinks,
    QDirIterator::Subdirectories);
    while (it.hasNext()) {
    qDebug() << it.filePath();
    it.next();
    }
    @

    The output looks something like

    Debug: "/accounts/1000/removable"
    Debug: "/accounts/1000/removable/.."
    Debug: "/accounts/1000/search"
    Debug: "/accounts/1000/shared"
    Debug: "/accounts/1000/shared/.."
    Debug: "/accounts/1000/shared/voice/.."
    Debug: "/accounts/1000/shared/protected_media"
    Debug: "/accounts/1000/sharewith"
    Debug: "/accounts/1000/sys"
    Debug: "/accounts/1000/sysdata"
    Debug: "/accounts/1000/appdata/sys.keyboard"
    Debug: "/accounts/1000/appdata/sys.airservices"
    Debug: "/accounts/1000/appdata/sys.navigator"
    Debug: "/accounts/1000/shared"
    Debug: "/accounts/1000/shared/.."

    The ones it repeats seem to be the ones it has permission to enter. How can I get it to not repeat directories and also not to display ".." and still recurse.

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

      Add QDir::NoDotAndDotDot to your flags.

      (Z(:^

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Dredvard
        wrote on last edited by
        #3

        That got rid of the ".." but still the repeat directories still exist.

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

          This is indeed strange, I don't know the reason for that. As a workaround, you can store the results in a QStringList and then call ::removeDuplicates().

          (Z(:^

          1 Reply Last reply
          0
          • D Offline
            D Offline
            Dredvard
            wrote on last edited by
            #5

            I'm using it as an interator so removing Duplicates doesn't quite work.

            I added the following to check for duplicates and it worked fine.

            if (!Pathlist.contains(it.filePath())){
            qDebug() << it.filePath();
            Pathlist<<it.filePath();

            So is this some sort of bug in Qdiriterator then?

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

              I have no idea, but certainly does not look like a design decision. I usually use ::entryInfoList myself, I don't remember this happening.

              You can report the bug on "JIRA":http://qt-project.org/wiki/ReportingBugsInQt. If you choose to do it, please post a link to the bug here so that we can follow it.

              (Z(:^

              1 Reply Last reply
              0
              • D Offline
                D Offline
                DerManu
                wrote on last edited by
                #7

                Not sure whether this has anything to do with the problems you're experiencing, but you should call the qDebug() output after the it.next() call. (See Qt documentation about their java-style iterators.)

                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