Here's my test case. Once up and running, I modified main.cpp twice. It works with no problems for me with Notepad. On the other hand, Visual Studio seems to have it's own way for "editing" files (the file system watcher notices the file being removed).
// main.cpp
#include <QtCore>
#include <QtDebug>
{
Q_OBJECT
public:
Watcher()
{
addPath
(QDir::current().
filePath("main.cpp"));
connect(this, SIGNAL(fileChanged(const QString&)), this, SLOT(fileChanged(const QString&)));
qDebug() << "monitoring" << files();
}
private slots:
void fileChanged(const QString& path)
{
qDebug() << "fileChanged" << path;
qDebug() << "-->" << files();
}
};
int main(int argc, char *argv[])
{
Watcher w;
return a.exec();
}
#include "main.moc"
// main.cpp
#include <QtCore>
#include <QtDebug>
class Watcher : public QFileSystemWatcher
{
Q_OBJECT
public:
Watcher()
{
addPath(QDir::current().filePath("main.cpp"));
connect(this, SIGNAL(fileChanged(const QString&)), this, SLOT(fileChanged(const QString&)));
qDebug() << "monitoring" << files();
}
private slots:
void fileChanged(const QString& path)
{
qDebug() << "fileChanged" << path;
qDebug() << "-->" << files();
}
};
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Watcher w;
return a.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode

Originally Posted by
Windows (notepad)
monitoring ("D:/Temp/Watcher/main.cpp")
fileChanged "D:/Temp/Watcher/main.cpp"
--> ("D:/Temp/Watcher/main.cpp")
fileChanged "D:/Temp/Watcher/main.cpp"
--> ("D:/Temp/Watcher/main.cpp")

Originally Posted by
Windows (vs)
monitoring ("D:/Temp/Watcher/main.cpp")
fileChanged "D:/Temp/Watcher/main.cpp"
--> ()

Originally Posted by
Linux
monitoring ("/home/jpn/temp/watcher/main.cpp")
fileChanged "/home/jpn/temp/watcher/main.cpp"
--> ("/home/jpn/temp/watcher/main.cpp")
fileChanged "/home/jpn/temp/watcher/main.cpp"
--> ("/home/jpn/temp/watcher/main.cpp")
Bookmarks