如果指定目录(或子文件夹)中的文件无需每次都获取所有修改时间,有什么方法可以触发操作?我问是因为我必须现场检查一下
最佳答案
您需要使用 QFileSystemWatcher。
更重要的是,这是您需要连接到的信号:
void QFileSystemWatcher::fileChanged(const QString & path) [signal]
This signal is emitted when the file at the specified path is modified, renamed or removed from disk.
See also directoryChanged().
所以,你可以在你的类或函数中写这样的东西:
...
QFileSystemWatcher watcher;
watcher.addPath("/My/Path/To/The/File");
QObject::connect(&watcher, SIGNAL(fileChanged(const QString&)), receiver, SLOT(handleFileChanged(const QString&)));
...
关于c++ - Qt:检查文件夹中的文件是否已更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22883218/