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

QFileSystemModel.remove does not remove directories recursively.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3: Somewhat important
    • Resolution: Done
    • Affects Version/s: 5.10.0
    • Fix Version/s: 5.11.0 Alpha
    • Component/s: Widgets: Itemviews
    • Labels:
      None
    • Environment:
      I use Qt 5.10.0 and windows 10. I use MSVC 2017 for 64 bits and MSVC 2015 for 32 bits.
    • Commits:
      0901d4290f6e7f0d1650b14fc085ecde7fb595ff (qtbase/dev, 26.1.2018, 5.11)

      Description

      I made a photo selection program with a QTreeView and a QFileSystemModel. If you click on a node you get a popupmenu with which you can delete, rename and make a new directory. Deleting recursivly doesn't work.

       

      I tried several ways to delete directories recursively.

      1. QFileSystemModel.remove

      code:

          QModelIndex current = fmodel->index(fpath);
          if (current.isValid())
          \{
              qint32 result = QMessageBox::question(this, "Delete?", "Are you sure you want to delete " + ffilename + " ?", QMessageBox::(Yes | QMessageBox::No);
              if (result == QMessageBox::Yes)
              \{
                  QModelIndex p = current.parent();
                  setCurrentIndex(p);
                  fmodel->remove(current);
              }
          }
      

      result:

      In a directory structure like this "d:\kwibus\new directory\new directory\new directory\new directory" and fpath pointing to "d:\kwibus\new directory wil only delete the last directory in a QTreeView. But when i just created a new directory and the directory structure is just like the one before it will delete two directories. Debug messages show that fpath and therefore current in the code sample point to "d:\kwibus\new directory".

      2. QDir.removeRecursivly()

      code:

          QModelIndex current = fmodel->index(fpath);
          if (current.isValid())
          \{
              qint32 result = QMessageBox::question(this, "Delete?", "Are you sure you want to delete " + ffilename + " ?", QMessageBox::Yes | QMessageBox::No);
              if (result == QMessageBox::Yes)
              \{
                  QModelIndex p = current.parent();
                  setCurrentIndex(p);
                  QDir dir(fpath);
                  dir.removeRecursively();
              }
          }
      

      result:

      In a directory structure like this "d:\kwibus\new directory\new directory\new directory\new directory" and fpath pointing to "d:\kwibus\new directory wil only delete the last 2 directories in a QTreeView. Debug messages show that fpath and therefore current in the code sample point to "d:\kwibus\new directory".

      I attached the sourcecode of the program. The code samples are located in directorytreeview.cpp

        Attachments

        For Gerrit Dashboard: QTBUG-65683
        # Subject Branch Project Status CR V

          Activity

            People

            Assignee:
            kleint Friedemann Kleint
            Reporter:
            haaften Roland van Haaften
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes