Details
-
Bug
-
Resolution: Done
-
P3: Somewhat important
-
5.4.2, 5.5.0 Beta
-
None
-
da46ea92e537501c932343f65e11032a2f5984f3 (qt/qtbase/5.14)
Description
Based on issues :
QTBUG-46431
QTBUG-24898
it appears that the QFileSystemWatcher's documentation may be improved.
Step to reproduce :
1/ create a watcher and add a file
2 / edit the file in an editor (works when using gedit)
3/ save the file
=> the signal fileChanged(QString) is emitted
BUT
=> the file is no more watched and the signal won't be emitted if the file is modified again if the file is modified again.
The reason is the following :
1/ In most editors, "save" is implemented with "delete the file / recreate the file".
2/ deleting the file causes the file to be removed from the watcher => it is no more monitored, even though the path is immediately recreated.
This behaviour is perfectly logical, and is not a bug.
But it is worth being mentioned in the documentation !!!
I propose to add something like the following to the QFileSystemWatcher doumentation :
Note : note that when "saving" a file, many editors actually delete the file, then recreate it. In that case, the QFileSystemWatcher will emit the fileChanged(QString) signal once. However, since the file is deleted, it will be removed from the monitored file list : future modification of the file won't be monitored anymore, since it is actually another file (though with the same path).
Workarround : when the fileChanged(QString) is received, check if the file has been removed from the monitored file list. If it has been removed, but if the path still exists on drive, readd the path to the monitored file list :if( ! watcher.files().contains(_fileName) && QFileInfo( _fileName).exists()) { m_watcher.addPath(_fileName); }
Attachments
Issue Links
- relates to
-
QTBUG-46431 signal QFileSystemWatcher::fileChanged is no more emitted after 1 or 2 modifications of the file
- Closed
-
QTBUG-24898 QFileSystemWatcher (inotify) and editors that rename files
- Closed
-
QTBUG-53607 QFileSystemWatcher: add note about gedit and vim
- Closed