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

tst_qfilesystemmodel relies on a specific QHash ordering

    XMLWordPrintable

Details

    • e6e4456de0506aa9896b687dc858eb9ae03d8917

    Description

      tst_QFileSystemModel::sort() test creates a couple of files into a temporary directory, then sorts the view by the file size.

      This correctly sorts the files, but the entries for the "." and ".." get sorted in an arbitrary order. The root cause seems to be this part from qfilesystemmodel.cpp

      
          QList<QPair<QFileSystemModelPrivate::QFileSystemNode*, int> > values;
          QHash<QString, QFileSystemNode *>::const_iterator iterator;
          int i = 0;
          for(iterator = indexNode->children.begin() ; iterator != indexNode->children.end() ; ++iterator) {
              if (filtersAcceptsNode(iterator.value())) {
                  values.append(QPair<QFileSystemModelPrivate::QFileSystemNode*, int>((iterator.value()), i));
              } else {
                  iterator.value()->isVisible = false;
              }
              i++;
          }
          QFileSystemModelSorter ms(column);
          qStableSort(values.begin(), values.end(), ms);
      
      

      where the items get added to a list in the hash order, then a stable sort is done on them; but the sorter won't enforce any order between "." and ".." (both are very likely to have the same size), therefore their order will be the one picked up by the iterator.

      On the contrary, down in the test, a specific order is expected:

          expectedOrder << tempFile2.fileName() << tempFile.fileName() << dirPath + QChar('/') + "." << dirPath + QChar('/') + "..";
      

      Attachments

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

        Activity

          People

            laknoll Lars Knoll
            peppe Giuseppe D'Angelo
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes