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

QFileSystemModel with QDir::Files shows last opened dirs in QListView

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 6.1.0
    • Widgets: Itemviews
    • None
    • Windows

    Description

      Here's the code:

      #include <QtWidgets>
      
      class Form : public QWidget
      {
          Q_OBJECT
      public:
          Form(QWidget *parent = nullptr) : QWidget(parent)
          {
              auto grid = new QGridLayout(this);
              auto list = new QListView;
              auto test = new QPushButton("Test Me");
              auto path = new QLineEdit("D:/test");
              grid->addWidget(list, 1, 0, 1, 3);
              grid->addWidget(test, 0, 2, 1, 1);
              grid->addWidget(path, 0, 0, 1, 2);
      
              auto model = new QFileSystemModel;
              model->setIconProvider(new QFileIconProvider);
              model->setFilter(QDir::Files);
              list->setModel(model);
              list->setRootIndex(model->setRootPath("D:/test"));
              connect(test, &QPushButton::clicked, [model, path, list] ()
              {
                  list->setRootIndex(model->setRootPath(path->text()));
              });
          }
      };
      
      //------------------------------------------------------------------------------
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          Form w;
          w.resize(400, 400);
          w.show();
          return a.exec();
      }
      
      

      I've created a class Form for testing this situation. When I am pressing the "Test Me" button, then form must show files in path given from the QLineEdit element. First I watch files in D:/Test directory, the list shows files in it, then go to D:/ and the list shows last opened Test directory. And if we go to D:/Home dir, and then again to D:/ list will show both Test and Home dirs. Though the filter is QDir::Files only, and it doesn't show any other folders in D:/.

        

         

       

       

       

      Attachments

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

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            alexnevskiy Alex Nevskiy
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes