QFileSystemWatcher watcher;
watcher.addPath("C:/watch");
QStringList directoryList = watcher.directories();
Q_FOREACH(QString directory, directoryList)
qDebug() << "Directory name" << directory <<"\n";
DirectoryWatcher* dw = new DirectoryWatcher;
QObject::connect(
&watcher, SIGNAL(directoryChanged(const QString&)),
dw, SLOT(modified(const QString&))
);
QObject::connect(
&watcher, SIGNAL(fileChanged(QString)),
dw, SLOT(modified(QString))
);
In this sample, modified() method called when;
- a new file created
- a file deleted
- a file renamed
But, If i open a file in this folder and modify the content, after I save it, nothing called.
IF I add that specific file to the path like addPath("c:/watch/me.txt")
then after modify it gets invoked.
But as you might know, there is a limitation on watcher. So I cannot watch hundreds of files every time.
How can I invoke modified() method on file modifications?