Connection guard (detected during #477)

Disconnects Qt signal/slot conenction when destroyed
This commit is contained in:
Klaus Basan
2015-10-31 01:17:37 +01:00
committed by Mathew Sutcliffe
parent 3acf085b92
commit 23856bbc57
11 changed files with 124 additions and 34 deletions

View File

@@ -21,7 +21,7 @@ namespace BlackMisc
{
CWebDataServicesAware::~CWebDataServicesAware()
{
disconnectSignals();
this->m_swiftConnections.disconnectAll();
}
CServerList CWebDataServicesAware::getVatsimFsdServers() const
@@ -264,7 +264,7 @@ namespace BlackMisc
void CWebDataServicesAware::setProvider(IWebDataServicesProvider *webDataReaderProvider)
{
Q_ASSERT_X(webDataReaderProvider, Q_FUNC_INFO, "missing provider");
disconnectSignals();
this->m_swiftConnections.disconnectAll();
m_webDataReaderProvider = webDataReaderProvider;
}
@@ -275,7 +275,7 @@ namespace BlackMisc
void CWebDataServicesAware::gracefulShutdown()
{
disconnectSignals();
this->m_swiftConnections.disconnectAll();
this->m_webDataReaderProvider = nullptr;
}
@@ -317,13 +317,5 @@ namespace BlackMisc
return this->m_webDataReaderProvider->readDbDataFromDisk(dir, inBackround);
}
void CWebDataServicesAware::disconnectSignals()
{
for (QMetaObject::Connection &c : m_swiftConnections)
{
QObject::disconnect(c);
}
m_swiftConnections.clear();
}
} // namespace
} // namespace

View File

@@ -26,6 +26,7 @@
#include "blackmisc/simulation/simulatedaircraft.h"
#include "blackmisc/weather/metarset.h"
#include "blackmisc/countrylist.h"
#include "blackmisc/connectionguard.h"
#include <functional>
@@ -343,8 +344,8 @@ namespace BlackMisc
CWebDataServicesAware(IWebDataServicesProvider *webDataReaderProvider = nullptr) : m_webDataReaderProvider(webDataReaderProvider) { }
private:
IWebDataServicesProvider *m_webDataReaderProvider = nullptr; //!< access to object
QList<QMetaObject::Connection> m_swiftConnections; //!< signal connection with swift
IWebDataServicesProvider *m_webDataReaderProvider = nullptr; //!< access to object
BlackMisc::CConnectionGuard m_swiftConnections; //!< signal connection with swift
//! Disconnect all signals
void disconnectSignals();