Windows で Qt 5.0.2 の QFileSystemWatcher に問題があります。
test.cpp
...
QFileSystemWatcher watcher;
watcher.addPath("C:/data/watch");
QStringList directoryList = watcher.directories();
Q_FOREACH(QString directory, directoryList)
qDebug() << "Directory name" << directory <<"\n";
DirectoryWatcher* dw = new DirectoryWatcher;
QObject::connect(
&watcher, SIGNAL(directoryChanged(const QString&)),
dw, SLOT(showModified(const QString&))
);
QObject::connect(
&watcher, SIGNAL(fileChanged(QString)),
dw, SLOT(showChanged(QString))
);
DirectoryWatcher.cpp
DirectoryWatcher::DirectoryWatcher(QWidget* parent) : QWidget(parent)
{
qDebug() << "monitoring" << endl;
}
void DirectoryWatcher::showModified(const QString& str) {
qDebug() << "Sending File" << str << endl;
}
void DirectoryWatcher::showChanged(const QString& str) {
qDebug() << "show changed " << str << endl;
}
私が直面している問題は、ファイルを「C:/data/watch」フォルダーに作成/移動/編集しているときでも、関数「showModified」または「showChanged」が呼び出されないことです。彼らは持っている
パラメータとして使用されるスロットの名前を存在しないものに変更すると、エラーが発生するため、スロットの名前は正しいと確信しています。
QObject::connect: No such slot DirectoryWatcher::showChangeds(QString) (kernel\qobject.cpp:2082, void err_method_notfound(const QObject*, const char*, const char*))
また、パスとして追加しているディレクトリが存在することも確信しています。
QStringList directoryList = watcher.directories();
Q_FOREACH(QString directory, directoryList)
qDebug() << "Directory name" << directory <<"\n";
ディレクトリを取得します:
Directory name "C:/data/watch"
ドキュメントには次のように明確に記載されています: ( http://qt-project.org/doc/qt-5.0/qtcore/qfilesystemwatcher.html#addPath )
Adds path to the file system watcher if path exists. The path is not added if it does not exist, or if it is already being monitored by the file system watcher.
明らかに私は何かが欠けています。誰かが私の間違いを指摘してくれたり、私の問題を解決するための別の解決策を提供してくれたりしてくれれば幸いです。
どうぞよろしくお願いいたします。ありがとうございました。