Table Of Contents

Previous topic

QSettings

Next topic

QThreadPool

QFileSystemWatcher

Inheritance diagram of QFileSystemWatcher

Synopsis

Functions

Signals

Detailed Description

The PySide.QtCore.QFileSystemWatcher class provides an interface for monitoring files and directories for modifications.

PySide.QtCore.QFileSystemWatcher monitors the file system for changes to files and directories by watching a list of specified paths.

Call PySide.QtCore.QFileSystemWatcher.addPath() to watch a particular file or directory. Multiple paths can be added using the PySide.QtCore.QFileSystemWatcher.addPaths() function. Existing paths can be removed by using the PySide.QtCore.QFileSystemWatcher.removePath() and PySide.QtCore.QFileSystemWatcher.removePaths() functions.

PySide.QtCore.QFileSystemWatcher examines each path added to it. Files that have been added to the PySide.QtCore.QFileSystemWatcher can be accessed using the PySide.QtCore.QFileSystemWatcher.files() function, and directories using the PySide.QtCore.QFileSystemWatcher.directories() function.

The PySide.QtCore.QFileSystemWatcher.fileChanged() signal is emitted when a file has been modified, renamed or removed from disk. Similarly, the PySide.QtCore.QFileSystemWatcher.directoryChanged() signal is emitted when a directory or its contents is modified or removed. Note that PySide.QtCore.QFileSystemWatcher stops monitoring files once they have been renamed or removed from disk, and directories once they have been removed from disk.

Note

On systems running a Linux kernel without inotify support, file systems that contain watched paths cannot be unmounted.

Note

Windows CE does not support directory monitoring by default as this depends on the file system driver installed.

Note

The act of monitoring files and directories for modifications consumes system resources. This implies there is a limit to the number of files and directories your process can monitor simultaneously. On Mac OS X 10.4 and all BSD variants, for example, an open file descriptor is required for each monitored file. Some system limits the number of open file descriptors to 256 by default. This means that PySide.QtCore.QFileSystemWatcher.addPath() and PySide.QtCore.QFileSystemWatcher.addPaths() will fail if your process tries to add more than 256 files or directories to the file system monitor. Also note that your process may have other file descriptors open in addition to the ones for files being monitored, and these other open descriptors also count in the total. Mac OS X 10.5 and up use a different backend and do not suffer from this issue.

class PySide.QtCore.QFileSystemWatcher([parent=None])
class PySide.QtCore.QFileSystemWatcher(paths[, parent=None])
Parameters:

Constructs a new file system watcher object with the given parent .

Constructs a new file system watcher object with the given parent which monitors the specified paths list.

PySide.QtCore.QFileSystemWatcher.addPath(file)
Parameters:file – unicode

Adds path to the file system watcher if path exists. The path is not added if it does not exist, or if it is already being monitored by the file system watcher.

If path specifies a directory, the PySide.QtCore.QFileSystemWatcher.directoryChanged() signal will be emitted when path is modified or removed from disk; otherwise the PySide.QtCore.QFileSystemWatcher.fileChanged() signal is emitted when path is modified, renamed or removed.

Note

There is a system dependent limit to the number of files and directories that can be monitored simultaneously. If this limit has been reached, path will not be added to the file system watcher, and a warning message will be printed to stderr .

PySide.QtCore.QFileSystemWatcher.addPaths(files)
Parameters:files – list of strings

Adds each path in paths to the file system watcher. Paths are not added if they not exist, or if they are already being monitored by the file system watcher.

If a path specifies a directory, the PySide.QtCore.QFileSystemWatcher.directoryChanged() signal will be emitted when the path is modified or removed from disk; otherwise the PySide.QtCore.QFileSystemWatcher.fileChanged() signal is emitted when the path is modified, renamed, or removed.

Note

There is a system dependent limit to the number of files and directories that can be monitored simultaneously. If this limit has been reached, the excess paths will not be added to the file system watcher, and a warning message will be printed to stderr for each path that could not be added.

PySide.QtCore.QFileSystemWatcher.directories()
Return type:list of strings

Returns a list of paths to directories that are being watched.

PySide.QtCore.QFileSystemWatcher.directoryChanged(path)
Parameters:path – unicode
PySide.QtCore.QFileSystemWatcher.fileChanged(path)
Parameters:path – unicode
PySide.QtCore.QFileSystemWatcher.files()
Return type:list of strings

Returns a list of paths to files that are being watched.

PySide.QtCore.QFileSystemWatcher.removePath(file)
Parameters:file – unicode

Removes the specified path from the file system watcher.

PySide.QtCore.QFileSystemWatcher.removePaths(files)
Parameters:files – list of strings

Removes the specified paths from the file system watcher.