QFileSystemWatcher 類

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

頭: #include <QFileSystemWatcher>
Since: Qt 4.2
繼承: QObject

注意: 此類的所有函數 可重入 .

公共函數

QFileSystemWatcher (QObject * parent = 0)
QFileSystemWatcher (const QStringList & paths , QObject * parent = 0)
~QFileSystemWatcher ()
void addPath (const QString & path )
void addPaths (const QStringList & paths )
QStringList directories () const
QStringList 文件 () const
void removePath (const QString & path )
void removePaths (const QStringList & paths )

信號

void directoryChanged (const QString & path )
void fileChanged (const QString & path )

額外繼承成員

詳細描述

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 () 以看守特定文件或目錄。可以添加多個路徑使用 addPaths () 函數。可以移除現有路徑通過使用 removePath () 和 removePaths () 函數。

QFileSystemWatcher examines each path added to it. Files that have been added to the QFileSystemWatcher can be accessed using the 文件 () 函數,和目錄使用 directories () 函數。

The fileChanged () 信號被發射當文件被修改、被重命名或從磁盤被移除時。同樣, 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.

注意: 在不支持 inotify 的運行 Linux 內核的係統,無法取消掛載包含看守路徑的文件係統。

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

另請參閱 QFile and QDir .

成員函數文檔編製

QFileSystemWatcher:: QFileSystemWatcher ( QObject * parent = 0)

構造新的文件係統看守程序對象采用給定 parent .

QFileSystemWatcher:: QFileSystemWatcher (const QStringList & paths , QObject * parent = 0)

構造新的文件係統看守程序對象采用給定 parent which monitors the specified paths 列錶。

QFileSystemWatcher:: ~QFileSystemWatcher ()

銷毀文件係統看守程序。

void QFileSystemWatcher:: addPath (const QString & path )

添加 path 到文件係統看守程序若 path 存在。路徑不被添加若路徑不存在 (或路徑已被文件係統看守程序所監視)。

path 指定目錄, directoryChanged () 信號將發射當 path 被修改或從磁盤被移除;否則 fileChanged () 信號發射當 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 ().

void QFileSystemWatcher:: addPaths (const QStringList & paths )

添加每個路徑在 paths 到文件係統看守程序。路徑不被添加若路徑不存在 (或路徑已被文件係統看守程序所監視)。

若路徑指定目錄, directoryChanged () 信號會被發射當路徑被修改或從磁盤被移除時;否則 fileChanged () 信號被發射當路徑被修改、被重命名或被移除時。

注意: 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 () const

返迴正被看守的目錄路徑列錶。

另請參閱 文件 ().

[signal] void QFileSystemWatcher:: directoryChanged (const QString & path )

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 ().

[signal] void QFileSystemWatcher:: fileChanged (const QString & path )

此信號被發射當文件在指定 path 被修改、被重命名或從磁盤被移除。

另請參閱 directoryChanged ().

QStringList QFileSystemWatcher:: 文件 () const

返迴正被看守的文件路徑列錶。

另請參閱 directories ().

void QFileSystemWatcher:: removePath (const QString & path )

移除指定 path 從文件係統看守程序。

另請參閱 removePaths () 和 addPath ().

void QFileSystemWatcher:: removePaths (const QStringList & paths )

移除指定 paths 從文件係統看守程序。

另請參閱 removePath () 和 addPaths ().