2

I'm developing an app on windows with Qt and I need to detect changes in a specific folder. So I used a QFileSystemWatcher, and I connect the directoryChanged signal to a function that will send a message in case of changes.

The problem is that the "slot" function connected to directoryChanged is not called if I modify a file's content, but only when a file or directory is removed or added.

However, the documentation says that this signal is emitted when "the directory at a specified path, is modified (e.g., when a file is added, modified or deleted) or removed from disk."

Does anyone have an explanation? Thanks in advance =)

lagarkane
  • 915
  • 2
  • 9
  • 22

1 Answers1

0

According to Qt source code version 4.8.2, as following:

void QFileSystemWatcherPrivate::_q_directoryChanged(const QString &path, bool removed)
{
    Q_Q(QFileSystemWatcher);
    if (!directories.contains(path)) {
        // perhaps the path was removed after a change was detected, but before we delivered the signal
        return;
    }
    if (removed)
        directories.removeAll(path);
    emit q->directoryChanged(path);
}

It seems that directoryChanged emit when a file removed, added(for the new added file not contains in directories), and renamed. The implementation does not guarantee to detect a modification of a file's content. Hope that helps :P

  • Thanks for this answer. So the QFileSystemWatch may not be the solution to my problem. – lagarkane Oct 31 '12 at 12:24
  • I could use FileChanged signal, and create a FileSystemWatcher on each file/directory in the fileSystem, but if the user have thousands of files in his directory, won't it be to heavy to check each of them manually? Is there any way to address this issue? – lagarkane Oct 31 '12 at 12:32
  • Actually, what I need is a way to be aware of changes in a possibly very heavy filesystem. I just made a test on windows: over 28000 files, the filesystemWatcher no longer support the load. (I'm not surprised, but I wonder: How does Dropbox-like programs handle this issue?) – lagarkane Oct 31 '12 at 14:16
  • Having the same problem at hand. Will need to implement a hand made watcher which will be set to watch a specified directory, will run in a separate thread, will be regularly triggered by a timer (e.g. each 5 seconds) and will check and record the modification time of the most recent file. During each regular check it will find all files which have the modification time later than the previously recorded time. I think this should not be that hard to implement. – HiFile.app - best file manager Nov 15 '17 at 18:02