Qt: check if the file is modified in the folder

Is there a way to initiate an action if the file is in the specified directory (or in a subfolder) without selecting all modification times each time? I ask because I have to check this live

+7
c ++ qt qfile qtcore qfilesystemwatcher
source share
2 answers

You need to use QFileSystemWatcher.

More importantly, this is the signal you need to connect to:

void QFileSystemWatcher :: fileChanged (const QString and path) [signal]

This signal is emitted when the file at the specified path is changed, renamed or deleted from the disk.

See also directoryChanged ().

So you can write something like this in your class or function:

... QFileSystemWatcher watcher; watcher.addPath("/My/Path/To/The/File"); QObject::connect(&watcher, SIGNAL(fileChanged(const QString&)), receiver, SLOT(handleFileChanged(const QString&))); ... 
+8
source share

You are looking for a QFileSystemWatcher .

+3
source share

All Articles