سؤال

How can one obtain the changed file names from the QFileSystemWatcher directoryChanged event?

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

المحلول

You need to connect your slot to the fileChanged() signal instead of directoryChanged() if you are more interested in the file names.

connect(&myFileSystemWatcher, SIGNAL(fileChanged(const QString&)), SLOT(handleFileChanged(const QString&)));

Then, you can just use the slot argument as desired. Here, I am just printing it out to stdout:

void handleFileChanged(const QString &path)
{
    qDebug() << path;
}

Please see the documentation for further details:

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.

Not sure how much you are familiar with the Qt signal/slot system, but if not enough, please go through this, too:

Qt Signals & Slots

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