Please look at this .h and .cpp, it shows an example ... greetings!
#ifndef MYCLASS_H #define MYCLASS_H #include <QWidget> #include <QMessageBox> class MyClass : public QWidget { Q_OBJECT public: MyClass(QWidget* parent=0) :QWidget(parent){} ~MyClass(){} public slots: void showModified(const QString& str) { Q_UNUSED(str) QMessageBox::information(this,"Directory Modified", "Your Directory is modified"); } }; #endif // MYCLASS_H #include <QApplication> #include <QFileSystemWatcher> #include <QDebug> #include "MyClass.h" int main(int argc, char* argv[]) { QApplication app(argc, argv); QFileSystemWatcher watcher; watcher.addPath("C:/QtTest"); QStringList directoryList = watcher.directories(); Q_FOREACH(QString directory, directoryList) qDebug() << "Directory name" << directory <<"\n"; MyClass* mc = new MyClass; QObject::connect(&watcher, SIGNAL(directoryChanged(QString)), mc, SLOT(showModified(QString))); return app.exec(); }
When you ever edit or create or delete a file or folder in the path "C: / QtTest", you will get a message box.
source share