문제

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