3

I'm currently using a QFileSystemWatcher to monitor a directory for any changes to the files contained within. This work great, but only when I change those files with certain programs.

For example, when I change a file using Qt Creator, the QFileSytemWatcher triggers correctly. If I edit and save the exact same file the exact same way using, say, Notepad++ or Eclipse, it doesn't trigger that the file is changed.

I'm fairly certain that this has to do with how the OS/programs handle write buffering. My program unfortunately doesn't have any control over how the writes are being done; any program can change the files I am monitoring. As a result, the only way that I can think of reliably detecting changes in files is by using a regular timer to scan for file changes (which is much less efficient than the OS watching files for me). Are there any better ways of doing this? Any help is appreciated.

Shookit
  • 1,162
  • 2
  • 13
  • 29
  • This question seems to be common for many frameworks, not just Qt-specific. – Alexander Stepaniuk Mar 28 '13 at 19:26
  • I probably could have generalized it; I'll mark it as a duplicate if I find a good generalized answer. – Shookit Mar 28 '13 at 19:27
  • If Qt provides any good solution here, it would be interesting to know that. So, probably, no need to mark it as duplicate :) – Alexander Stepaniuk Mar 28 '13 at 19:31
  • Sounds good! As an aside, this is a pretty good summary of what I've already stated, in case this helps anyone down the road: http://stackoverflow.com/questions/239988/filesystemwatcher-vs-polling-to-watch-for-file-changes/240008#240008 – Shookit Mar 28 '13 at 19:33
  • It also has to do with how the OS watches files; on linux, it uses inotify when available (inotify is new-ish), which can be set to watch for certain kinds of changes (I have a script that watches for changes using inotifywait, and it works with a myriad of different ways that programs modify files). Also, apparently this is going to be [fixed in 5.1](http://blog.rburchell.com/2012/03/qt-51-aka-when-qfilesystemwatcher-might.html) – forivall Mar 28 '13 at 20:14
  • It could have to do with wheter file/directory modification/access time is updated or not. It happened once that I disabled last-access timestamp on each directory with NtfsDisableLastAccessUpdate and file system watcher stops working correctly. – bkausbk Jul 16 '13 at 06:34

0 Answers0