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

QFileSystemModel (temporarily) contains duplicate entries

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 4.7.4, 5.6.2
    • None

    Description

      Unfortunately this bug seems to depend on a particular flow of events, which means I wasn't able to create a minimal sample to demonstrate it.
      Essentially what we are doing is this:
      1) call QFileSystemModel::fetchMore()
      2) call QApplication::processEvents() until the directoryLoaded signal has been emited for the directory(s) we are interrested in
      3) process the childnodes

      At step three the List of files looked like this: ["foo", "bar", "baz", "qux", "bar", "baz"]
      The two duplicate files would then vanish after further invocations of processEvents (probably due to the delayed sorting of the model).

      After converting the code to use persistent model indices the following assertion was triggered:

      ASSERT failure in QPersistentModelIndex::~QPersistentModelIndex: "persistent model indexes corrupted", file kernel/qabstractitemmodel.cpp, line 544

      I eventually traced the problem to QFileSystemModelPrivate::_q_fileSystemChanged()

      This method builds a list of updated files, as well as a list of new files.
      It then emits QFileSystemModel::dataChanged() for the updated files, and afterwards appends the new files to the parent node.
      Our dataChanged() signal handler apparently caused some some updates of the parent node as well and thus some of the new files were already present at this point, resulting in the above list with duplicates.

      In the attached patch I have simply changed the order so that the new files are added before any signal handler is executed, which has solved the issue for me.

      Attachments

        1. qfsmodel_add_before_update.patch
          0.9 kB
          Andy Kittner
        2. qtbug21278.zip
          3 kB
          Friedemann Kleint
        3. qtbug-21278-reproducer-mappu04.zip
          2 kB
          mappu

        Issue Links

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

          Activity

            People

              kleint Friedemann Kleint
              andkit Andy Kittner
              Votes:
              2 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes