Skip to content

Instantly share code, notes, and snippets.

@filcuc
Created October 20, 2018 13:10
Show Gist options
  • Save filcuc/a33f564ec070924aab721fc913d14b2a to your computer and use it in GitHub Desktop.
Save filcuc/a33f564ec070924aab721fc913d14b2a to your computer and use it in GitHub Desktop.
#include <QCoreApplication>
#include <QDebug>
#include <QFileSystemWatcher>
#include <QThread>
#include <QTimer>
#include <cstdlib>
#include <QProcess>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QFileSystemWatcher watcher;
QObject::connect(&watcher, &QFileSystemWatcher::directoryChanged, [&](const QString& changed){
qDebug() << "Changed DIRECTORY" << changed << " and watcher monitor the following dirs" << watcher.directories() << "and files "<< watcher.files();
});
QObject::connect(&watcher, &QFileSystemWatcher::fileChanged, [&](const QString& changed){
qDebug() << "Changed FILE " << changed << " and watcher monitor the following dirs" << watcher.directories() << "and files "<< watcher.files();
});
QTimer timer;
QObject::connect(&timer, &QTimer::timeout, [&] {
::system("rm -rf /tmp/test");
::system("mkdir -p /tmp/test/subdir");
::system("touch /tmp/test/subdir/subfile.txt");
watcher.addPath("/tmp/test/");
watcher.addPath("/tmp/test/subdir");
watcher.addPath("/tmp/test/subdir/subfile.txt");
::system("mv /tmp/test/subdir /tmp/test/subdir2");
QThread::currentThread()->wait(1000);
::system("echo \"OK\" >> /tmp/test/subdir2/subfile.txt");
});
timer.setSingleShot(true);
timer.start(2000);
return a.exec();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment