سؤال

There any way to trigger an action if a file in a specified directory ( or in a subfolder ) without fetching all modification times every time ? I'm asking because i've to check this live

هل كانت مفيدة؟

المحلول

You need to use the QFileSystemWatcher.

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

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().

So, you could 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&)));
...

نصائح أخرى

You're looking for QFileSystemWatcher.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top