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] Data not updated after folder renaming
Forum Updated to NodeBB v4.3 + New Features

[QFileSystemModel] Data not updated after folder renaming

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 276 Views 1 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.
  • N Offline
    N Offline
    nico88desmo
    wrote on last edited by
    #1

    Dear all,

    I'm facing the following problem: after a folder has been renamed, QFileSystemModel stop to watch changing on that folder.

    Here is my setup:

    • KUbuntu 22.04
    • Qt 6.2.7

    In more details: I'm using QFileSystemModel to show the content of a folder path; everything is working correctly up to I renamed (from external) a folder.

    Example:
    Starting from this situation:

    Folder A
    |--- Folder B
    |------ Folder B1
    |------ Folder B2
    |--- Folder C
    

    I rename Folder B in Folder BNew

    Folder A
    |--- Folder BNew
    |------ Folder B1
    |------ Folder B2
    |--- Folder C
    

    At this point, data model are still ok.

    Now, I create Folder B3 (from OS) inside the renamed folder Folder BNew, the model isn't updated (i.e. Folder B3 doesn't appear)

    Folder A
    |--- Folder BNew
    |------ Folder B1
    |------ Folder B2
    |------ Folder B3 (created from OS, but FilesSystemModel doesn't 'see' it)
    |--- Folder C
    

    If I rename back Folder BNew to Folder B, in this way model is correctly updated.

    From doc I read that QFileSystemModel internally is using a QFileSystemWatcher and a cache. QFileSystemWatcher doesn't monitor delete folders or renamed/delete files (written here).

    Moreover, I see that this problem has beed already reported stackoverflow-66141880 and QTBUG-33720.

    My question is:

    • have you got any suggestions on how to clear internal cache?
    • Is there any workaround that let me update a folder after I renamed it?

    I try also to reset setRootPath(..), but as written here, this function doesn't change underlay data model

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      The patches linked in the bug report seem to provide a solution but the original submitter seem to not have pushed through.
      You could apply them to your Qt version to do what you need.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • N Offline
        N Offline
        nico88desmo
        wrote on last edited by
        #3

        Hi @SGaist,

        thanks for the quick answer.
        Unfortunately I haven't had time to test this patch; however I confirm that, in current situation (I think this persists in latest Qt versions too), the problem is that the model data inside QFileSystemModel isn't aligned to the real folder status, and this appears in case a folder/file has been renamed/deleted from external (such as OS file manager).

        Is it the case to open again the bug? Or is it better to open a new one?

        1 Reply Last reply
        0
        • N Offline
          N Offline
          nico88desmo
          wrote on last edited by
          #4

          I'm trying to understand better what's happening: so I try to use directly the QFileSystemWatcher.
          Supposing the following scenario:

          Folder A
          --- Folder B
          

          now I add the path Folder A -> Folder B to a QFileSystemWatcher's instance; everything I change within Folder B is correctly notified thanks directoryChange() signal.
          Now I rename Folder B to Folder BB and I create another Folder B:

          Folder A
          --- Folder BB (previous Folder B)
          --- Folder B
          

          Supposing having this capture:

          connect(&fsWatcher, &QFileSystemWatcher::directoryChanged, this, [&](const lString& path) {
             std::cout << path;
          });
          

          if I change something on Folder BB, the value printed is Folder B.
          This is quite reasonable, because at the beginning I added Folder B to QFileSystemWatcher's instance; however, cause signal notifiy a change just using the string Folder B, it seems that something changes on new Folder B; and this may broke the relation between Qt and real file system status.

          1 Reply Last reply
          0

          • Login

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