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. QFileSystemModel is not updating correctly when setting filter for hidden items
Forum Updated to NodeBB v4.3 + New Features

QFileSystemModel is not updating correctly when setting filter for hidden items

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 1.6k Views
  • 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.
  • C Offline
    C Offline
    cristeab
    wrote on last edited by
    #1

    Hi

    I am using Qt 5.12.3 MS VS2017 on Windows Server 2016 x64. I am using a QFileSystemModel to show the file system and I have added an option to hide or show hidden items (files or folders). I have noticed that when the file permissions are set in File Explorer my application does not update correctly QFileSystemModel (it seems that the model does not detect the permissions change done from outside the application). Only by restarting the application I get the correct file system model.

    This bug report refers to a similar issue:

    https://bugreports.qt.io/browse/QTBUG-12413?jql=text ~ "QFileSystemModel"

    Could someone shed more light into this problem ?

    thanks
    Bogdan

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Can you please create a minimal, compilable example so we can reproduce this, thx.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • C Offline
        C Offline
        cristeab
        wrote on last edited by cristeab
        #3

        In the sample below (tested on Windows Server 2016 x64 with VS 2017 x64 and Qt 5.13.2) a root folder is set in order to install a file system watcher on it. The root folder contains another folder in it (initially this folder is not hidden). Start the application: should show the number of items in the root folder. From Windows Explorer change the folder attributes to hidden. This change is not detected by the file system model, but if you restart the application you will notice that the number of items in the root folder is decreased by one (i.e the hidden folder is detected).

        Instead of restarting the application you might try to change the name of the hidden folder (the layout is not changed) or the name of another item (layout is changed and the number of items is shown correctly).

        I would expect that this change in folder attributes to be detected, especially the hidden attribute change, since this has an impact on how the items are shown in a Tree view for example. Maybe someone could propose a solution for this problem.

        #include <QGuiApplication>
        #include <QFileSystemModel>
        #include <QDebug>
        
        int main(int argc, char *argv[])
        {
            QGuiApplication a(argc, argv);
        
            QFileSystemModel model;
            const auto filters = (QDir::AllEntries | QDir::NoDotAndDotDot) & ~QDir::Hidden;
            model.setFilter(static_cast<QDir::Filters>(filters));
            const QString path = "E:/projects/temp";
            model.setRootPath(path);
            QObject::connect(&model, &QFileSystemModel::layoutChanged, [&]() {
                qInfo() << "layoutChanged" << model.rowCount(model.index(path));
            });
        
            return a.exec();
        }
        
        1 Reply Last reply
        1
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by Christian Ehrlicher
          #4

          Now I understand - so it's not a limitation of QFileSystemModel but QFileSystemWatcher. Looking at the code you can see that QFileSystemWatcher does not watch for attribute changes of directories:
          https://code.woboq.org/qt5/qtbase/src/corelib/io/qfilesystemwatcher_win.cpp.html#403 , for a list of possible flags see here: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-findfirstchangenotificationa

          I would say it's an oversight and should be fixed especially since the inotify backend seems to watch for attribute changes of directories: https://code.woboq.org/qt5/qtbase/src/corelib/io/qfilesystemwatcher_inotify.cpp.html#285

          Could not find a bug report about this so feel free to create one and link to this threat.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          2
          • C Offline
            C Offline
            cristeab
            wrote on last edited by
            #5

            @Christian-Ehrlicher thank you for your quick reply

            1 Reply Last reply
            0
            • C Offline
              C Offline
              cristeab
              wrote on last edited by
              #6

              I have an additional question: using Windows API it is possible to detect the the item attribute change, but how can I force an update on QFileSystemModel ?

              1 Reply Last reply
              0
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @cristeab said in QFileSystemModel is not updating correctly when setting filter for hidden items:

                but how can I force an update on QFileSystemModel ?

                You can't - you currently need to recreate the model

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                JonBJ 1 Reply Last reply
                0
                • Christian EhrlicherC Christian Ehrlicher

                  @cristeab said in QFileSystemModel is not updating correctly when setting filter for hidden items:

                  but how can I force an update on QFileSystemModel ?

                  You can't - you currently need to recreate the model

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #8

                  @Christian-Ehrlicher
                  If you didn't want to recreate, could you use setRootPath() (maybe twice, somewhere else then back to where it was) to get it to restart monitoring the directory, so that it would refresh and see the changed attribute?

                  Christian EhrlicherC 1 Reply Last reply
                  0
                  • JonBJ JonB

                    @Christian-Ehrlicher
                    If you didn't want to recreate, could you use setRootPath() (maybe twice, somewhere else then back to where it was) to get it to restart monitoring the directory, so that it would refresh and see the changed attribute?

                    Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @JonB It's checking if it's the same path, so yes no need to set it to something else and revert it back. Or better - write a bugreport so it gets fixed in QFileSystemWatcher :)

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    1 Reply Last reply
                    2

                    • Login

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