0

Hi all I want to use QFileSystemWatcher to watch changes of a given directory and its subdirectory recursively, but void QFileSystemWatcher::addPath ( const QString & path ) didn't let me do it so is there any idea to do it easily or I should implement it by my self (extract all directories and subdirectories and files under to added with void QFileSystemWatcher::addPaths ( const QStringList & paths ))?

Any help will be appreciated.

Thank you in advance.

Morten Kristensen
  • 7,412
  • 4
  • 32
  • 52
Oumaya
  • 655
  • 4
  • 18
  • 43

1 Answers1

2

The documentation of class QFileSystemWatcher doesn't state that recursive watching is part of its contract. So I think a solution might be, as you hinted, to walk the directory tree yourself, gather all sub-directories and their files in a string list and use

void QFileSystemWatcher::addPaths ( const QStringList & paths )

Also, I think it might be useful for you to mention which version of qt you are working with, because according to this thread, QFileSystemWatcher is being deprecated and a new api is supposed to replace it.

b2Wc0EKKOvLPn
  • 2,054
  • 13
  • 15
  • Hi, thank you for your response, am using QtSdk-v1_2_1(QT 4.8.1), `Old prototype: void QFileSystemWatcher::addPath ( const QString & path )` is provided, so I think I will proceed it by my self,thank you one more time . – Oumaya Oct 07 '12 at 10:08
  • 1
    This is an [example](http://my.safaribooksonline.com/book/programming/qt/0596000642/working-with-files-and-directories/prowqt2-chp-11-sect-2) illustrating how to walk a directory using **QDir**. You can easily adapt it to suit your needs. – b2Wc0EKKOvLPn Oct 07 '12 at 17:32
  • 3
    One thing to watch out for if you're adding a subtree this way... According to the QFileSystemWatcher documentation: "Some system limits the number of open file descriptors to 256 by default." If I understand correctly, this means that if there are more than 256 subdirectories, this approach will fail on some systems. – Michael Cooper Jan 30 '14 at 03:13