Search code examples
qtqfilesystemwatcher

Qt QFileSystemWatcher on Windows


I have the following issue: I create a QFileSystemWatcher and it runs and works nicely on Linux, but no way on Windows 7. Can you spot anything in the code that might make it not to work?

Thx.

Here is the code to initialize it:

mConfigChangeWatcher = new QFileSystemWatcher();
mConfigChangeWatcher->addPath(config_file_name);

QObject::connect(mConfigChangeWatcher,
                 SIGNAL(fileChanged(QString)),
                 this,
                 SLOT(configFileChanged(QString)));

and this is supposed to be the slot getting the work done:

void MyClass::configFileChanged(const QString &file)
{
    qDebug() << "Changed: " << file ;
}

Solution

  • When you check if the file is added to the watcher using QFileSystemWatcher::files() method after the first modification in the file do you get the correct list?

    I was with the issue that some applications, when modifing a file, delete the old file from the system and write it again.

    Note that QFileSystemWatcher stops monitoring files once they have been renamed or removed from disk, and directories once they have been removed from disk.

    I was using QFileSystemWatcher to watch an image file edited by Photoshop. Somehow the file gets removed from the list of files being watched.