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. Program does not work properly using QFileSystemModel and QTreeView (Qt 6.7.2) under Windows 11
Forum Updated to NodeBB v4.3 + New Features

Program does not work properly using QFileSystemModel and QTreeView (Qt 6.7.2) under Windows 11

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 422 Views 2 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.
  • Z Offline
    Z Offline
    Zbigniew-Sch
    wrote on last edited by Zbigniew-Sch
    #1

    Hi,

    Has anyone used QFileSystemModel with QTreeView (Qt 6.7.2) under Windows 11?
    I copy JPG files in Windows Explorer and delete them, then the program hangs. It worked fine under Windows 10.
    I wrote a small test program and the result is the same, program hangs.

    jsulmJ 1 Reply Last reply
    0
    • Z Zbigniew-Sch

      Hi,

      Has anyone used QFileSystemModel with QTreeView (Qt 6.7.2) under Windows 11?
      I copy JPG files in Windows Explorer and delete them, then the program hangs. It worked fine under Windows 10.
      I wrote a small test program and the result is the same, program hangs.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Zbigniew-Sch said in Program does not work properly using QFileSystemModel mit QTreeView (Qt 6.7.2) unter Windows 11:

      I wrote a small test program and the result is the same, program hangs

      You should share it, so others can see what exactly you're doing and reproduce the issue.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • Z Offline
        Z Offline
        Zbigniew-Sch
        wrote on last edited by
        #3
        ////////////////////////////////////////////////////////////////////
        // Header file
        ////////////////////////////////////////////////////////////////////
        #include <QtWidgets/QMainWindow>
        #include <QFileSystemModel>
        
        class QTreeView;
        class QFileSystemModel;
        class QBoxLayout;
        class QModelIndex;
        class TestFileSystemModel : public QMainWindow
        {
            Q_OBJECT
        
        public:
            TestFileSystemModel(QWidget *parent = nullptr);
            ~TestFileSystemModel();
        
            QTreeView *m_pcoTreeView;
            QFileSystemModel *m_pcoModel;
            QWidget *m_pcoMainWidget;
            QBoxLayout* m_pcoMainLayout;
            QModelIndex m_coRootModelIndex;
        
        };
        
        ////////////////////////////////////////////////////////////////////
        // Cpp program
        ////////////////////////////////////////////////////////////////////
        TestFileSystemModel::TestFileSystemModel(QWidget *parent)
            : QMainWindow(parent)
        {
            resize(1400, 800);
            show();
        
            m_pcoModel = new QFileSystemModel(this);
            m_pcoMainWidget = new QWidget(this);
            m_pcoMainLayout = new QHBoxLayout();
        
            m_pcoMainLayout->setContentsMargins(0, 0, 0, 0);
        
            m_pcoTreeView = new QTreeView(m_pcoMainWidget);
            m_pcoTreeView->resize(width(), height());
        
            m_coRootModelIndex = m_pcoModel->setRootPath("D:\\TestFolder");
            m_pcoTreeView->setModel(m_pcoModel);
            m_pcoTreeView->setRootIndex(m_coRootModelIndex);
        
            m_pcoMainWidget->setLayout(m_pcoMainLayout);
            this->setCentralWidget(m_pcoMainWidget);
        }
        
        TestFileSystemModel::~TestFileSystemModel()
        {
            delete m_pcoMainWidget;
            delete m_pcoTreeView;
            delete m_pcoMainLayout;
            delete m_pcoModel;
        }
        
        Pl45m4P 1 Reply Last reply
        0
        • Z Zbigniew-Sch
          ////////////////////////////////////////////////////////////////////
          // Header file
          ////////////////////////////////////////////////////////////////////
          #include <QtWidgets/QMainWindow>
          #include <QFileSystemModel>
          
          class QTreeView;
          class QFileSystemModel;
          class QBoxLayout;
          class QModelIndex;
          class TestFileSystemModel : public QMainWindow
          {
              Q_OBJECT
          
          public:
              TestFileSystemModel(QWidget *parent = nullptr);
              ~TestFileSystemModel();
          
              QTreeView *m_pcoTreeView;
              QFileSystemModel *m_pcoModel;
              QWidget *m_pcoMainWidget;
              QBoxLayout* m_pcoMainLayout;
              QModelIndex m_coRootModelIndex;
          
          };
          
          ////////////////////////////////////////////////////////////////////
          // Cpp program
          ////////////////////////////////////////////////////////////////////
          TestFileSystemModel::TestFileSystemModel(QWidget *parent)
              : QMainWindow(parent)
          {
              resize(1400, 800);
              show();
          
              m_pcoModel = new QFileSystemModel(this);
              m_pcoMainWidget = new QWidget(this);
              m_pcoMainLayout = new QHBoxLayout();
          
              m_pcoMainLayout->setContentsMargins(0, 0, 0, 0);
          
              m_pcoTreeView = new QTreeView(m_pcoMainWidget);
              m_pcoTreeView->resize(width(), height());
          
              m_coRootModelIndex = m_pcoModel->setRootPath("D:\\TestFolder");
              m_pcoTreeView->setModel(m_pcoModel);
              m_pcoTreeView->setRootIndex(m_coRootModelIndex);
          
              m_pcoMainWidget->setLayout(m_pcoMainLayout);
              this->setCentralWidget(m_pcoMainWidget);
          }
          
          TestFileSystemModel::~TestFileSystemModel()
          {
              delete m_pcoMainWidget;
              delete m_pcoTreeView;
              delete m_pcoMainLayout;
              delete m_pcoModel;
          }
          
          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on last edited by Pl45m4
          #4

          @Zbigniew-Sch

          There is so much unnecessary stuff going on in your code...
          and maybe you describe what you are doing before it "hangs" or when it crashes?

          #include <QFileSystemModel>
          
          class QFileSystemModel;
          

          Why forward-declare if you include it anyway?

              resize(1400, 800);
              show();
              // ...
              // ...
              this->setCentralWidget(m_pcoMainWidget);
          

          Why show() before the content is created and the centralWidget is set?!
          The human eye is probably not able to spot any difference since it might be just milisecs, but the other way round would be better.

              m_pcoTreeView->resize(width(), height());
          

          Resizing a widget in a layout might have no effect, since the size is managed by the layout and size hints.

              delete m_pcoMainWidget;
              delete m_pcoTreeView;
              delete m_pcoMainLayout;
              delete m_pcoModel;
          

          No need to delete any of these widgets manually. They are all childs or grandchildren of your TestFileSystemModel QMainWindow.
          So they will be removed with their parent QObject.


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          1 Reply Last reply
          1
          • Z Offline
            Z Offline
            Zbigniew-Sch
            wrote on last edited by
            #5

            Thanks for the tips, but that's not the problem.
            The program runs and I copy 2-3 JPG files and then I delete them in the directory "D:\TestFolder"
            (not in my program) in Windows Explorer and now the program hangs

            Pl45m4P 1 Reply Last reply
            0
            • Z Zbigniew-Sch

              Thanks for the tips, but that's not the problem.
              The program runs and I copy 2-3 JPG files and then I delete them in the directory "D:\TestFolder"
              (not in my program) in Windows Explorer and now the program hangs

              Pl45m4P Offline
              Pl45m4P Offline
              Pl45m4
              wrote on last edited by
              #6

              @Zbigniew-Sch said in Program does not work properly using QFileSystemModel and QTreeView (Qt 6.7.2) under Windows 11:

              then I delete them in the directory "D:\TestFolder"
              (not in my program) in Windows Explorer and now the program hangs

              Usually the QFileSystemModel has an internal QFileSystemWatcher which keeps track of changes made to the files.
              If the same code works on Win 10 and everywhere else, it's maybe a bug.


              If debugging is the process of removing software bugs, then programming must be the process of putting them in.

              ~E. W. Dijkstra

              1 Reply Last reply
              0
              • Z Offline
                Z Offline
                Zbigniew-Sch
                wrote on last edited by
                #7

                Are you from the Qt development team?
                Maybe someone from the Qt development team would like to comment on this problem.

                Pl45m4P 1 Reply Last reply
                0
                • Z Zbigniew-Sch

                  Are you from the Qt development team?
                  Maybe someone from the Qt development team would like to comment on this problem.

                  Pl45m4P Offline
                  Pl45m4P Offline
                  Pl45m4
                  wrote on last edited by Pl45m4
                  #8

                  @Zbigniew-Sch said in Program does not work properly using QFileSystemModel and QTreeView (Qt 6.7.2) under Windows 11:

                  Are you from the Qt development team?

                  This is a user forum... most people here are users like you with more or less experience.
                  Debug your app to see why and where it crashes.
                  If you think it's a bug related to QFileSystemModel and Win11, create a bugreport here


                  If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                  ~E. W. Dijkstra

                  1 Reply Last reply
                  1

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved