FileSystemWatcher & FileSystemWatcher::instance()
{
- // This thread-safe because QFileSystemWatcher is thread-safe.
+ // This is thread-safe because QFileSystemWatcher is thread-safe.
static FileSystemWatcher f;
return f;
}
}
-FileMonitorBlockerGuard::FileMonitorBlockerGuard(FileMonitor * parent)
- : QObject(parent), parent_(parent), delay_(0)
+FileMonitorBlockerGuard::FileMonitorBlockerGuard(FileMonitor * monitor)
+ : monitor_(monitor), delay_(0)
{
- QObject::disconnect(parent_->monitor_.get(), SIGNAL(fileChanged()),
- parent_, SLOT(changed()));
+ QObject::disconnect(monitor->monitor_.get(), SIGNAL(fileChanged()),
+ monitor, SLOT(changed()));
}
FileMonitorBlockerGuard::~FileMonitorBlockerGuard()
{
- // closures can only copy local copies
- FileMonitor * parent = parent_;
- // parent is also our QObject::parent() so we are deleted before parent.
+ if (!monitor_)
+ return;
// Even if delay_ is 0, the QTimer is necessary. Indeed, the notifications
// from QFileSystemWatcher that we meant to ignore are not going to be
// treated immediately, so we must yield to give us the opportunity to
// ignore them.
- QTimer::singleShot(delay_, parent, SLOT(connectToFileMonitorGuard()));
+ QTimer::singleShot(delay_, monitor_, SLOT(reconnectToFileMonitorGuard()));
}
} // namespace support
#include <QFileSystemWatcher>
#include <QObject>
+#include <QPointer>
#include <boost/signals2.hpp>
class FileMonitorBlockerGuard : public QObject
{
Q_OBJECT
- FileMonitor * parent_;
+ QPointer<FileMonitor> monitor_;
int delay_;
public:
- FileMonitorBlockerGuard(FileMonitor * parent);
+ FileMonitorBlockerGuard(FileMonitor * monitor);
~FileMonitorBlockerGuard();
void setDelay(int delay);
};