With 5.0 now being feature frozen, I thought I’d turn myself towards something I’ve been meaning to do (and talking about doing) for a very long time. Back before the Qt Project launched, even before Qt Contributors Summit 2011, in fact. I thought I’d make QFileSystemWatcher more useful.
Let’s review what QFileSystemWatcher offers: a way to add and remove paths for monitoring directories and files, a directoryChanged(path) and a fileChanged(path) signal. That’s it. If you think about this for a moment, you realise just how broken the semantics of the signals are: what _is_ a ‘change’ anyway? I guess this is one of the reasons that QFileSystemWatcher has been called ‘deprecated’ (I fixed one of the others, a performance issue, a while back).
So I’ve been working on making the signals a bit less useless. In the longer run, I plan to call fileChanged and directoryChanged deprecated. They’ll still be emitted (of course) to keep existing code working, but in addition, you’ll have (subject to review):
pathCreated(path) – emitted when something is created inside a directory you are monitoring, or if something that didn’t exist that you were monitoring for is created (more on this later)
pathDeleted(path) – emitted when something is deleted inside a directory you were monitoring, or something that you _were_ monitoring was deleted
fileModified(path) – emitted when a file you were monitoring is modified (attributes or contents)
I also have early plans to introduce a pathMoved(oldLocation, newLocation), but that one has a lot of caveats: it might only work on certain platforms, in certain phases of the moon, and only if you’re very lucky – on many platforms, it will likely continue to be synthesised as a pathDeleted(oldPath) and pathCreated(newPath) (if you’re watching the new location).