[vlmc-devel] Settings: Use unique_ptr for m_settingsFile

Yikai Lu git at videolan.org
Mon Jul 17 17:42:28 CEST 2017


vlmc | branch: master | Yikai Lu <luyikei.qmltu at gmail.com> | Mon Jul 17 17:27:09 2017 +0200| [ddf699bb67ed91597a5ec3f859e2c52392cdaca3] | committer: Yikai Lu

Settings: Use unique_ptr for m_settingsFile

> https://code.videolan.org/videolan/vlmc/commit/ddf699bb67ed91597a5ec3f859e2c52392cdaca3
---

 src/Settings/Settings.cpp | 6 ++----
 src/Settings/Settings.h   | 4 +++-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/Settings/Settings.cpp b/src/Settings/Settings.cpp
index 2bc8f927..d1b06125 100644
--- a/src/Settings/Settings.cpp
+++ b/src/Settings/Settings.cpp
@@ -55,13 +55,11 @@ Settings::Settings( const QString &settingsFile )
 Settings::~Settings()
 {
     qDeleteAll( m_settings );
-    delete m_settingsFile;
 }
 
 void
 Settings::setSettingsFile( const QString &settingsFile )
 {
-    delete m_settingsFile;
     if ( settingsFile.isEmpty() == false )
     {
         QFileInfo fInfo( settingsFile );
@@ -71,10 +69,10 @@ Settings::setSettingsFile( const QString &settingsFile )
             if ( dir.exists() == false )
                 dir.mkpath( fInfo.absolutePath() );
         }
-        m_settingsFile = new QFile( settingsFile );
+        m_settingsFile.reset( new QFile( settingsFile ) );
     }
     else
-        m_settingsFile = nullptr;
+        m_settingsFile.release();
 }
 
 QJsonDocument
diff --git a/src/Settings/Settings.h b/src/Settings/Settings.h
index d1f5ce8f..def54acb 100644
--- a/src/Settings/Settings.h
+++ b/src/Settings/Settings.h
@@ -27,6 +27,8 @@
 #include "Project/Project.h"
 #include "SettingValue.h"
 
+#include <memory>
+
 #include <QString>
 #include <QMap>
 #include <QPair>
@@ -125,7 +127,7 @@ class   Settings: public QObject
     private:
         SettingMap                  m_settings;
         mutable QReadWriteLock      m_rwLock;
-        QFile*                      m_settingsFile;
+        std::unique_ptr<QFile>      m_settingsFile;
 
         QList<QPair<QString, Settings*>>                 m_settingsChildren;
 



More information about the Vlmc-devel mailing list