QFileSystemWatcher Class Reference

[ QtCore module]

The QFileSystemWatcher class provides an interface for monitoring files and directories for modifications. 更多...

继承 QObject .

方法

Qt Signals


详细描述

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

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

调用 addPath () 到 watch a particular file or directory. Multiple paths can be added 使用 addPaths () function. Existing paths can be removed by using the removePath () 和 removePaths () 函数。

QFileSystemWatcher examines each path added to it. Files that have been added to the QFileSystemWatcher can be accessed using the 文件 () function, and directories using the directories () 函数。

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

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

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

注意: 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 addPath () 和 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.


方法文档编制

QFileSystemWatcher.__init__ ( self , QObject   parent  = None)

parent argument, if not None, causes self to be owned by Qt instead of PyQt.

构造新的文件系统看守程序对象采用给定 parent .

QFileSystemWatcher.__init__ ( self , QStringList  paths , QObject   parent  = None)

parent argument, if not None, causes self to be owned by Qt instead of PyQt.

构造新的文件系统看守程序对象采用给定 parent which monitors the specified paths list.

QFileSystemWatcher.addPath ( self , QString  file )

添加 path 到文件系统看守程序若 path exists. The path is not added if it does not exist, or if it is already being monitored by the file system watcher.

path 指定目录, directoryChanged () signal will be emitted when path is modified or removed from disk; otherwise the fileChanged () signal is 被发射当 path 被修改、被重命名或被移除。

注意: 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 .

另请参阅 addPaths () 和 removePath ().

QFileSystemWatcher.addPaths ( self , QStringList  文件 )

添加每个路径在 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.

若路径指定目录, directoryChanged () signal will be emitted when the path is modified or removed from disk; otherwise the fileChanged () signal is emitted when the path is modified, renamed, or removed.

注意: 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.

另请参阅 addPath () 和 removePaths ().

QStringList QFileSystemWatcher.directories ( self )

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

另请参阅 文件 ().

QStringList QFileSystemWatcher.files ( self )

返回正被看守的文件路径列表。

另请参阅 directories ().

QFileSystemWatcher.removePath ( self , QString  file )

移除指定 path from the file system watcher.

另请参阅 removePaths () 和 addPath ().

QFileSystemWatcher.removePaths ( self , QStringList  文件 )

移除指定 paths from the file system watcher.

另请参阅 removePath () 和 addPaths ().


Qt Signal Documentation

void directoryChanged (const QString&)

This is the default overload of this signal.

This signal is emitted when the directory at a specified path , is modified (e.g., when a file is added, modified or deleted) or removed from disk. Note that if there are several changes during a short period of time, some of the changes might not emit this signal. However, the last change in the sequence of changes will always generate this signal.

另请参阅 fileChanged ().

void fileChanged (const QString&)

This is the default overload of this signal.

此信号被发射当文件在指定 path 被修改、被重命名或从磁盘被移除。

另请参阅 directoryChanged ().