PDA

View Full Version : QFileSystemWatcher fileChanged signal doubling



roxton
15th May 2008, 20:53
There is something wrong with a "fileChanged" signal at QFileSystemWatcher. I'm working on the text editor. The opened file is added to the monitoring files list using the QFileSystemWatcher::addPath. When the other program changes this file, I get TWO "fileChanged" signals instead of a one. What's wrong? I've tested it, edited the monitoring file in different editors, but the result is the same - two signals are emmited after the changes was done.

elcuco
15th May 2008, 21:52
you are using a single QFileSystemWatcher for several editor? or one per editor?

roxton
16th May 2008, 11:26
Sure, I use a single QFileSystemWatcher instance. My editor is multy-tabbed. When it opens a file, it add a file path to QFileSystemWatcher:

watcher.addPath (file_name);

When an editor closes a file, I remove the file path from QFileSystemWatcher.

jpn
16th May 2008, 12:09
What does


qDebug() << watcher.files() << watcher.directories();

output?

roxton
16th May 2008, 12:27
If I call it from my fileChanged-slot, I get this:
-----------
("/home/rox/devel/test/test.txt") ()
("/home/rox/devel/test/test.txt") ()
-----------
It's after saving test.txt once from the another, external editor.

jpn
16th May 2008, 12:31
Ok. What's the name of the slot? Perhaps you used the naming convention of automatic connections by accident?

on_objectName_signalName(...)

roxton
16th May 2008, 14:01
My slot is named as "watcher_fileChanged". I have a class that manage text documets - document_holder. Withing that class I have a public slot document_holder::watcher_fileChanged (const QString & path).
At the document_holder constructor I call the "connect" method to connect a slot with a watcher:

connect(&watcher, SIGNAL(fileChanged(const QString &)), this, SLOT(watcher_fileChanged (const QString &)));

All that compiles under Linux. And Qt is 4.3.4