{
if (!monitoring()) {
monitor_ = FileSystemWatcher::activeMonitor(filename_);
+ // Disconnected at the same time as this is destroyed.
monitor_->connect([this](bool /* exists */){ changed_(); });
}
}
void FileMonitor::connectToFileMonitorGuard()
{
+ // Connections need to be asynchronous because the receiver can own this
+ // object and therefore is allowed to delete it.
+ // Qt signal:
QObject::connect(monitor_.get(), SIGNAL(fileChanged(bool)),
+ this, SIGNAL(fileChanged(bool)),
+ Qt::QueuedConnection);
+ // Boost signal:
+ QObject::connect(this, SIGNAL(fileChanged(bool)),
this, SLOT(changed(bool)));
}
}
-void FileMonitor::disconnect()
-{
- fileChanged_.disconnect_all_slots();
- QObject::disconnect(this, SIGNAL(fileChanged(bool)));
-}
-
-
void FileMonitor::changed(bool const exists)
{
// emit boost signal
fileChanged_(exists);
- Q_EMIT fileChanged(exists);
}
}
}
if (changed)
- FileMonitor::changed(exists);
+ Q_EMIT FileMonitor::fileChanged(exists);
QTimer::singleShot(interval_, this, SLOT(clearCooldown()));
}
/// monitor.connect(...);
/// (stops watching the first)
///
-/// Reset connections:
-/// monitor.disconnect();
-/// or the disconnect method of the connection object for the boost signal.
-///
class FileSystemWatcher
{
public:
typedef sig::slot_type slot;
/// Connect and you'll be informed when the file has changed.
signals2::connection connect(slot const &);
- /// disconnect all slots connected to the boost signal fileChanged_ or to
- /// the qt signal fileChanged()
- void disconnect();
/// absolute path being tracked
std::string const & filename() { return monitor_->filename(); }
/// Make sure the good file is being monitored, after e.g. a move or a