October 11, 2011

mirswith mirswith
Lab Rat
125 posts

QFileSystemWatcher QDir::remove locking

 

According to QFileSystemWatcher it will emit it’s directoryChanged signal when a path is removed, which it does … sort of. It emits the signal but the folder is not reporting that it has been removed using QDir::exists. If I try browsing to the folder with windows explorer it shows the directory but gives me an access denied if I try entering it. I’m running Windows 7 ×64 btw. To test if QFileSystemWatcher was locking it I put together this quick sample:

  1. QDir dir("c:/temp");
  2. qDebug() << "mkpath  test1/test2/test3" << dir.mkpath("test1/test2/test3");
  3. QFileSystemWatcher watch(QStringList() << dir.absoluteFilePath("test1") << dir.absoluteFilePath("test1/test2") << dir.absoluteFilePath("test1/test2/test3"));
  4. qDebug() << "rmdir - test1/test2/test3" << dir.rmdir("test1/test2/test3");
  5. qDebug() << "rmdir - test1/test2" << dir.rmdir("test1/test2");
  6. qDebug() << "rmdir - test1" << dir.rmdir("test1");

Which outputs…

  1. mkpath  test1/test2/test3 true
  2. rmdir - test1/test2/test3 true
  3. QFileSystemWatcher: FindNextChangeNotification failed!! (Access is denied.)
  4. rmdir - test1/test2 false
  5. rmdir - test1 false

If I comment out the QFileSystemWatcher line then all the folders are removed successfully or if I remove the paths from the QFileSystemWatcher before I delete them then it will also succeed. What confuses me is that the docs say “Note that QFileSystemWatcher stops monitoring files once they have been renamed or removed from disk, and directories once they have been removed from disk.”. I was hoping to use QFileSystemWatcher to be my notifier when directories were removed, otherwise I have to build my own hooks to notify the “watcher” when things have changed. Any ideas?

Thanks.

0 replies

 
  ‹‹ Not able to center text veritical using painter.      how to access QT element from different file ››

You must log in to post a reply. Not a member yet? Register here!