PDA

View Full Version : Broken QFileSystemWatcher in Qt 4.2.3 under Windows?



No-Nonsense
21st March 2007, 14:18
I am using QFileSystemWatcher in my application to react on file changes of files in use that occur outside of my application.

With Qt 4.2.3 I do not get the fileChanged signal anymore from the QFileSystemWatcher.

Is this a bug? I searched http://www.trolltech.com/developer/task-tracker for QFileSystemWatcher but did not find anything on this issue.

Thanks in advance,
-Jens

Note: Under Linux it works as expected so I assume it must be a bug with Qt for Windows.

jpn
27th March 2007, 20:40
With Qt 4.2.3 I do not get the fileChanged signal anymore from the QFileSystemWatcher.

Is this a bug? I searched http://www.trolltech.com/developer/task-tracker for QFileSystemWatcher but did not find anything on this issue.
Well, I gave it a shot and it works for me. :) Do you explicitly add the files to be monitored, not just directories?

No-Nonsense
28th March 2007, 00:44
Well, I gave it a shot and it works for me. :) Do you explicitly add the files to be monitored, not just directories?

Yes, I am adding files. I have a debug console to which I can dump the QFileSystemWacher::files() at any time. It contains the full path with filename and extension to the monitored files. When doing changes to these files ouside of my app (e.g. using notepad) the ::fileCanged(const QString & file) is not emitted (I have a qDebug to my debugging console that should show the filename).

It worked before Qt 4.2.3, but I can not say for sure that the problem cam with this version. But it is working under correctly under Linux and another of my apps does have the same issue.

I diffed QFileSystemWatcher 4.2.2 agains 4.2.3 and there were no changes for Windows so it must be some other thing... Funny is that it works in QDevelop (the IDE notices changes of files beeing edited).

-Jens

jpn
28th March 2007, 09:22
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>

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"





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")




monitoring ("D:/Temp/Watcher/main.cpp")
fileChanged "D:/Temp/Watcher/main.cpp"
--> ()




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")

No-Nonsense
28th March 2007, 14:14
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).

Thanks! Your demonstration works without any problems on my Windows with Qt 4.2.3. I have to take a look if the filename added to the QFileSystemWatcher is really ok in my app. But I assue it is, as my app gets correctly notified under Linux...

-Jens