PDA

View Full Version : Using QFileSystemWatcher to detect which type of file changes happened



corrado1972
30th July 2010, 23:24
Hello you all,
Here (http://www.qtcentre.org/threads/5627-how-to-get-the-added-file-name-when-using-QFileSystemWatcher) I've totally understood why qfilesystemwatcher does not provide a new file added informations when some folder monitored changes.
So, I want write a cross platform process/daemon/win32 service that do this task.
I thinked to write a class that contains a qfilesystemwatcher that monitor some folders and signals every changement. I want to save a list of all files of every folder, and compare it with a second "image" of directory files. The differences can lead me to detect which kind of modification happened to the folder watched.

Here is the main loop as I intend it:
1) start monitoring a folder, take the snapshot of the files presents into the folder.
2) when signal is raised, take second snapshot of files list, and do the comparison, determining which files are modified, deleted and added since the first snapshot.
3) moving the second snapshot to the first, and wait for next signal, then repeat to the point 2

Is this the correct QT way to do this in cross platform manner?
Or could you suggest me a better solution?
Which QT classes should I use to do the folder comparison, QDir?

I know that this solution will not perform much, but I don't mind of performances.
I need a simple solution to capture everz new files added to a folder with low changements in the timespawn.

GreenScape
30th July 2010, 23:34
Which QT classes should I use to do the folder comparison, QDir?

you should create tree for each root folder, and save here checksums(qChecksum()) for each file in root and it's subdirectories and so on, then compare it i think.

borisbn
31st July 2010, 19:34
you can save QFileInfo list and when QFileSystemWatcher says, that something changed, compare only timestamp of files in monitored dir. And yes, use QDir for your task, bat aware a situation, when QDir monitors network shared folders, because it has very poor performance.

corrado1972
2nd August 2010, 07:32
@borisbn
Thankyou for the suggestion, I will take care about performances of QfilesytemWatcher network monitoring.

corrado1972
3rd August 2010, 07:17
I've found this qt project: http://blog.giowisys.com/?p=51 that seems good. I'lltake a look at the sources.
bye