0

I'm using QFileSystemWatcher for watching for changes in a directory that I set in watcher->addPath("myPath") method.

When I call watcher->directories() I see myPath.

But when I call watcher->files() I see nothing. I thought I will see files in directory when I use this method.

What should I do to see files in a directory?

Ezee
  • 4,214
  • 1
  • 14
  • 29
bin-bin
  • 532
  • 2
  • 6
  • 16

1 Answers1

2

QFileSystemWatcher is intended to watch changes in the file system.

To obtain a list of files in a directory use QDir::entryList.

Example:

QString files = QDir("c:\\").entryList(QDir::NoDotAndDotDot);

If you need to watch changes in a directory (file added/renamed or removed events) you use addPath with a directory and listen to directoryChanged signal.
If you need to watch a file content change you use addPath with a full path to a file and listen to fileChanged signal.

Accordingly directories returns a list of directories you have added and files returns a list of files you have added.

Ezee
  • 4,214
  • 1
  • 14
  • 29
  • I listen signal that you show, but my slot doesn't responds because of empty list of files - so this signal doesn't emit when I add some files to directory:( – bin-bin Oct 17 '14 at 11:50
  • There is nothing in common between `directoryChanged` and method `files`. Use `QDir` to obtain a list of files. – Ezee Oct 17 '14 at 11:57