PDA

View Full Version : QFileSystemWatcher no fileChanged signal



Talei
17th December 2011, 13:01
Hello,
I have QFileSystemWatcher and problem with it.
Signal fileChanged(QString) is never emited, but directoryChanged(QString) is emited.
The list of files fileWatcher->files() is empty.
I added path with file count less then 256, there is like 5files.

Any idea why is that happening? QFileSystemWatcher->directories() list all directories that I added and there is no error.

Platform Windows.
Thanks for reply.

Lesiok
17th December 2011, 14:45
I have any problems with QFileSystemWatcher. Show some code.

Talei
18th December 2011, 02:21
someClass::someClass(){ // <- constructor
fw = new QFileSystemWatcher( this );
connect( fw, SIGNAL(fileChanged(QString)), this, SLOT( fileChangedSlot(QString)) ); // <- never emit
// connect( fw, SIGNAL(directoryChanged(QString)), this, SLOT( fileChangedSlot(QString)) ); //emit but files() is empty, directories() is ok, I can see d:/test

fw->addPath( "D:/test" );
qDebug() << fw->files() << fw->directories(); // outputs: () ("D:/test") in test ther are file


}

void someClass::fileChangedSlot(QString fileName)
{
#ifdef QT_DEBUG
qDebug() << "files watched: " << fw->files() << fw->directories();
#endif

}

if I delete test directory, then:

QFileSystemWatcher: FindNextChangeNotification failed!! (Access is denied.)

So QFileSystemWatcher don't add files in that directory to "watch list" (there is 6files)
I have no idea why is that happening, I even changed parent for this obj. without any help.

Lykurg
18th December 2011, 07:18
the file change signal is emited when you change the name of the directory. And the files() are empty because you only have added a path to watch... You will be notified about file changes inside that directory through directoryChanged(). Note the argument!

... and the QT_DEBUG madness ...

Talei
18th December 2011, 10:03
I don't know why but I thought that addPath() will scan directory and add all files in that dir. ...

Everything works fine, as always user mistake with Qt usage.

Btw. why QT_DEBUG madness? I don't want qDebug() I release.

Lykurg
18th December 2011, 10:32
I don't want qDebug() I release.Everyone want that, so Qt is taking care that the debug message is suppressed in release mode. Even if they have change the default behavior, you can simply define QT_NO_DEBUG_OUTPUT in your pro file as well as QT_NO_WARNING_OUTPUT to mute them. No need to enclose all calls with a preprocessor statement.

Talei
18th December 2011, 11:05
I didn't know that QT_NO_DEBUG_OUTPUT will remove qDebug() line.
Thanks again.