From a6cdba17f0184ca8cb872859b908f8a6acde8ed0 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Fri, 7 Feb 2020 15:19:23 +0800 Subject: [PATCH] Fix singleton class ownership We shouldn't allow Qt parent ownership in here. --- src/app/application.cpp | 2 +- src/base/scanfoldersmodel.cpp | 10 +++------- src/base/scanfoldersmodel.h | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/app/application.cpp b/src/app/application.cpp index 0a3c254b3..81986c4e0 100644 --- a/src/app/application.cpp +++ b/src/app/application.cpp @@ -550,7 +550,7 @@ int Application::exec(const QStringList ¶ms) #ifndef DISABLE_COUNTRIES_RESOLUTION Net::GeoIPManager::initInstance(); #endif - ScanFoldersModel::initInstance(this); + ScanFoldersModel::initInstance(); #ifndef DISABLE_WEBUI m_webui = new WebUI; diff --git a/src/base/scanfoldersmodel.cpp b/src/base/scanfoldersmodel.cpp index c44ad5ccd..4e912cf5f 100644 --- a/src/base/scanfoldersmodel.cpp +++ b/src/base/scanfoldersmodel.cpp @@ -57,14 +57,10 @@ struct ScanFoldersModel::PathData ScanFoldersModel *ScanFoldersModel::m_instance = nullptr; -bool ScanFoldersModel::initInstance(QObject *parent) +void ScanFoldersModel::initInstance() { - if (!m_instance) { - m_instance = new ScanFoldersModel(parent); - return true; - } - - return false; + if (!m_instance) + m_instance = new ScanFoldersModel; } void ScanFoldersModel::freeInstance() diff --git a/src/base/scanfoldersmodel.h b/src/base/scanfoldersmodel.h index fb1925ab9..38bc13569 100644 --- a/src/base/scanfoldersmodel.h +++ b/src/base/scanfoldersmodel.h @@ -65,7 +65,7 @@ public: CUSTOM_LOCATION }; - static bool initInstance(QObject *parent = nullptr); + static void initInstance(); static void freeInstance(); static ScanFoldersModel *instance();