Home · All Namespaces · All Classes · Grouped Classes · Modules · Functions |
The QFileMonitor class allows applications to asynchronously monitor files for changes. More...
#include <QFileMonitor>
Inherits QObject.
The QFileMonitor class allows applications to asynchronously monitor files for changes.
Using QFileMonitor, clients will be notified through the fileChanged() signal when the contents of a file are changed, the file is deleted or when the file is created.
The QFileMonitor uses different mechanisms for monitoring file changes depending on the capabilities of the underlying system. The following methods are presently available:
DNotify
DNotify is available on all Linux kernels in the 2.4 series and later. Monitoring a file using DNotify has the consequence of "pinning" the containing directory until the QFileMonitor instance has been destroyed. A pinned directory cannot be removed and the filesystem exporting it cannot be unmounted.
In order to detect directory removal, the DNotify strategy must poll directories for existance once every 5 seconds.
INotify
INotify is available in Linux kernel versions 2.6.13 and later. Unlike DNotify, use of INotify does not pin the containing directory. If a directory is removed, while monitoring contained files the QFileMonitor will emit a fileChanged() signal as expected. However, should the directory be recreated the QFileMonitor will not resume monitoring files within it. The QFileMonitor instance must be destroyed and recreated for monitoring to resume.
Poll
While polling files for change is available on all systems, it is the least responsive strategy. Every 5 seconds the QFileMonitor manually polls all monitored files for changes. Polling should only be used as a last-resort fallback.
To avoid race conditions when using QFileMonitor to trigger re-reading of file contents, you should always construct QFileMonitor and only then read the initial file contents.
Represents the monitoring strategy being used by the QFileMonitor instance.
Constant | Value | Description |
---|---|---|
QFileMonitor::Auto | 0 | The best available monitoring strategy will be automatically selected. The instance will attempt, in order, to use INotify, DNotify and finally Polling. |
QFileMonitor::DNotify | 1 | The DNotify strategy is being used. |
QFileMonitor::INotify | 2 | The INotify strategy is being used. |
QFileMonitor::Poll | 3 | The Polling strategy is being used. |
QFileMonitor::None | 4 | No monitoring strategy is in use. |
Constructs an invalid file monitor with the specified parent.
Constructs a file monitor for the file fileName using the specified file monitoring strategy and parent.
Destroys the file monitor.
Emitted whenever the files contents change, the file is created or the file is removed. file is set to the name of the monitored file.
Returns the name of the file being monitored.
Returns true if the file is being actively monitored.
Returns the method used to monitor files.
Copyright © 2009 Nokia | Trademarks | Qt Extended 4.4.3 |