Monitors a specified directory for file additions or deletions at regular intervals. More...
#include <FileMonitor.h>
Signals | |
void | newFiles (const QStringList &files) |
Signal emitted when new files are detected in the monitored directory. | |
void | deletedFiles (const QStringList &files) |
Signal emitted when files are detected as deleted from the monitored directory. | |
void | monitoringChanged (const QString &path) |
Signal emitted when the monitored directory path changes. | |
void | monitoringIntervalChanged (const int new_interval) |
Signal emitted when the monitoring scan interval changes. | |
void | monitoringStateChanged (const bool new_state) |
Signal emitted when the monitoring state (active/inactive) changes. | |
Public Member Functions | |
FileMonitor (const QString &path, QObject *parent=nullptr) | |
Constructs a FileMonitor object. | |
void | setMonitorDirent (const QString &newPath) |
Sets the directory path to be monitored. | |
QString | monitorDirent () const |
Returns the current directory path being monitored. | |
void | setMonitorScanInterval (const int interval) |
Sets the interval (in milliseconds) at which the directory will be scanned. | |
int | monitorScanInterval () const |
Returns the current monitoring scan interval. | |
void | setMonitoringState (bool st) |
Sets the monitoring state (active or inactive). | |
bool | monitoringState () const |
Returns the current monitoring state. | |
Monitors a specified directory for file additions or deletions at regular intervals.
The FileMonitor class provides a mechanism to observe a given directory and detect changes within it, specifically the creation of new files or the deletion of existing ones. It operates by periodically scanning the directory and comparing its current state with a previously recorded state. Signals are emitted upon detecting changes, or when its monitoring parameters (path, interval, state) change. Thread-safe access to internal state is ensured using a QMutex.
|
explicit |
Constructs a FileMonitor object.
path | The initial directory path to monitor. |
parent | A pointer to the parent QObject, allowing for proper object hierarchy and memory management. Defaults to nullptr. |
|
signal |
Signal emitted when files are detected as deleted from the monitored directory.
files | A QStringList containing the absolute paths of the deleted files. |
QString FileMonitor::monitorDirent | ( | ) | const |
Returns the current directory path being monitored.
|
signal |
Signal emitted when the monitored directory path changes.
path | The new path being monitored. |
|
signal |
Signal emitted when the monitoring scan interval changes.
new_interval | The new scan interval in milliseconds. |
bool FileMonitor::monitoringState | ( | ) | const |
Returns the current monitoring state.
|
signal |
Signal emitted when the monitoring state (active/inactive) changes.
new_state | The new monitoring state (true for active, false for inactive). |
int FileMonitor::monitorScanInterval | ( | ) | const |
Returns the current monitoring scan interval.
|
signal |
Signal emitted when new files are detected in the monitored directory.
files | A QStringList containing the absolute paths of the newly detected files. |
void FileMonitor::setMonitorDirent | ( | const QString & | newPath | ) |
Sets the directory path to be monitored.
monitoringChanged
signal is emitted. newPath | The new directory path to monitor. |
void FileMonitor::setMonitoringState | ( | bool | st | ) |
Sets the monitoring state (active or inactive).
monitoringStateChanged
signal is emitted upon state change. st | True to start monitoring, false to stop. |
void FileMonitor::setMonitorScanInterval | ( | const int | interval | ) |
Sets the interval (in milliseconds) at which the directory will be scanned.
monitoringIntervalChanged
signal is emitted. interval | The new scan interval in milliseconds. |