[QFileSystemModel] Data not updated after folder renaming
-
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 CI rename
Folder BinFolder BNewFolder A |--- Folder BNew |------ Folder B1 |------ Folder B2 |--- Folder CAt this point, data model are still ok.
Now, I create
Folder B3(from OS) inside the renamed folderFolder BNew, the model isn't updated (i.e.Folder B3doesn't appear)Folder A |--- Folder BNew |------ Folder B1 |------ Folder B2 |------ Folder B3 (created from OS, but FilesSystemModel doesn't 'see' it) |--- Folder CIf I rename back
Folder BNewtoFolder B, in this way model is correctly updated.From doc I read that
QFileSystemModelinternally is using aQFileSystemWatcherand a cache.QFileSystemWatcherdoesn'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 -
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. -
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 insideQFileSystemModelisn'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?
-
I'm trying to understand better what's happening: so I try to use directly the
QFileSystemWatcher.
Supposing the following scenario:Folder A --- Folder Bnow I add the path
Folder A -> Folder Bto aQFileSystemWatcher's instance; everything I change withinFolder Bis correctly notified thanksdirectoryChange()signal.
Now I renameFolder BtoFolder BBand I create anotherFolder B:Folder A --- Folder BB (previous Folder B) --- Folder BSupposing having this capture:
connect(&fsWatcher, &QFileSystemWatcher::directoryChanged, this, [&](const lString& path) { std::cout << path; });if I change something on
Folder BB, the value printed isFolder B.
This is quite reasonable, because at the beginning I addedFolder BtoQFileSystemWatcher's instance; however, cause signal notifiy a change just using the stringFolder B, it seems that something changes on newFolder B; and this may broke the relation between Qt and real file system status.