]> git.lyx.org Git - lyx.git/commitdiff
Correct ownership
authorGuillaume Munch <gm@lyx.org>
Sat, 18 Mar 2017 19:37:55 +0000 (20:37 +0100)
committerGuillaume Munch <gm@lyx.org>
Sun, 19 Mar 2017 13:41:17 +0000 (14:41 +0100)
One can now delete a file monitor if a blocker is active.

src/support/FileMonitor.cpp
src/support/FileMonitor.h

index bf53f379edacd5580cca9b1544fdd09da0895418..c14d3d6e3a3e11d8b574f54d6e3d7bf6d0a94cb7 100644 (file)
@@ -31,7 +31,7 @@ namespace support {
 
 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;
 }
@@ -190,11 +190,11 @@ FileMonitorBlocker FileMonitor::block(int delay)
 }
 
 
-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()));
 }
 
 
@@ -206,14 +206,13 @@ void FileMonitorBlockerGuard::setDelay(int delay)
 
 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
index deca740657b5867dcf599b48e21d68d93bb27630..768e61f8733f91254895efca25e6259ab8818de2 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <QFileSystemWatcher>
 #include <QObject>
+#include <QPointer>
 
 #include <boost/signals2.hpp>
 
@@ -132,11 +133,11 @@ private:
 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);
 };