QFileSystemWatcher: detects removed & added files but not modified one

4.2k views Asked by At

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 =)

1

There are 1 answers

4
Möhler F. Zweig On

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