[Interest] QFileSystemWatcher malfunctioning

Andreas Pakulat apaku at gmx.de
Thu Jan 12 11:08:33 CET 2012


On 12.01.12 09:14:33, Bo Thorsen wrote:
> Den 12-01-2012 08:35, Andreas Pakulat skrev:
> > On 12.01.12 08:01:17, Sujan Dasmahapatra wrote:
> >> Dear Friends
> >>
> >> I am using QFileSystemWatcher for knowing when the file is modified from
> >> outside my application. I am seeing even if the file is modified from
> >> the application this is giving message that the file is modified. Can
> >> anyone tell whats going wrong in this..see the snippet below
> >
> > There is nothing going wrong here, thats how QFileSystemWatcher is
> > intended to work. If you don't want to be notified for changes you're
> > doing yourself you need to add code for that in your application.
> 
> And this is of course the task for a SignalBlocker. I've done exactly 
> this (block QFileSystemWatcher) for a customer a couple of months ago, 
> and it really is the only solution.

That only works as long as the detection of changes happens immediately,
that might not be the case all the time since it depends on which
backend QFSWatcher uses (there's a polling one). Usually I add a
modification-timestamp check to the system, i.e. store the
modification-time right after modifying the file and then compare when
the QFSWatcher triggers. This is of course not a 100% safe solution
(hashing the file would be even better) but in my experience good
enough.

Andreas




More information about the Interest mailing list