mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-07 02:35:33 +08:00
Connection guard (detected during #477)
Disconnects Qt signal/slot conenction when destroyed
This commit is contained in:
committed by
Mathew Sutcliffe
parent
3acf085b92
commit
23856bbc57
@@ -149,10 +149,10 @@ namespace BlackCore
|
||||
|
||||
QList<QMetaObject::Connection> CAirspaceMonitor::connectRemoteAircraftProviderSignals(
|
||||
QObject *receiver,
|
||||
std::function<void(const CAircraftSituation &)> situationSlot,
|
||||
std::function<void(const CAircraftSituation &)> situationSlot,
|
||||
std::function<void(const BlackMisc::Aviation::CCallsign &, const CAircraftParts &)> partsSlot,
|
||||
std::function<void(const CCallsign &)> removedAircraftSlot,
|
||||
std::function<void(const CAirspaceAircraftSnapshot &)> aircraftSnapshotSlot
|
||||
std::function<void(const CCallsign &)> removedAircraftSlot,
|
||||
std::function<void(const CAirspaceAircraftSnapshot &)> aircraftSnapshotSlot
|
||||
)
|
||||
{
|
||||
Q_ASSERT_X(receiver, Q_FUNC_INFO, "Missing receiver");
|
||||
|
||||
@@ -35,12 +35,14 @@ namespace BlackCore
|
||||
this->setObjectName("Simulator:" + info.getIdentifier());
|
||||
|
||||
// provider signals
|
||||
m_remoteAircraftProviderConnections = this->m_remoteAircraftProvider->connectRemoteAircraftProviderSignals(
|
||||
m_remoteAircraftProviderConnections.append(
|
||||
this->m_remoteAircraftProvider->connectRemoteAircraftProviderSignals(
|
||||
this, // receiver must match object in bind
|
||||
std::bind(&CSimulatorCommon::ps_remoteProviderAddAircraftSituation, this, std::placeholders::_1),
|
||||
std::bind(&CSimulatorCommon::ps_remoteProviderAddAircraftParts, this, std::placeholders::_1, std::placeholders::_2),
|
||||
std::bind(&CSimulatorCommon::ps_remoteProviderRemovedAircraft, this, std::placeholders::_1),
|
||||
std::bind(&CSimulatorCommon::ps_recalculateRenderedAircraft, this, std::placeholders::_1));
|
||||
std::bind(&CSimulatorCommon::ps_recalculateRenderedAircraft, this, std::placeholders::_1))
|
||||
);
|
||||
|
||||
// timer
|
||||
this->m_oneSecondTimer.setObjectName(this->objectName().append(":m_oneSecondTimer"));
|
||||
@@ -219,14 +221,7 @@ namespace BlackCore
|
||||
void CSimulatorCommon::unload()
|
||||
{
|
||||
this->disconnectFrom(); // disconnect from simulator
|
||||
|
||||
// disconnect as many signals as possible
|
||||
for (const QMetaObject::Connection &c : m_remoteAircraftProviderConnections)
|
||||
{
|
||||
QObject::disconnect(c);
|
||||
}
|
||||
m_remoteAircraftProviderConnections.clear();
|
||||
this->disconnect();
|
||||
this->m_remoteAircraftProviderConnections.disconnectAll();
|
||||
CLogHandler::instance()->disconnect();
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "blackmisc/network/textmessage.h"
|
||||
#include "blackmisc/network/client.h"
|
||||
#include "blackmisc/pixmap.h"
|
||||
#include "blackmisc/connectionguard.h"
|
||||
#include <QObject>
|
||||
|
||||
namespace BlackCore
|
||||
@@ -137,7 +138,7 @@ namespace BlackCore
|
||||
bool setInitialAircraftSituation(BlackMisc::Simulation::CSimulatedAircraft &aircraft) const;
|
||||
|
||||
protected:
|
||||
IInterpolator *m_interpolator = nullptr; //!< interpolator instance
|
||||
IInterpolator *m_interpolator = nullptr; //!< interpolator instance
|
||||
bool m_pausedSimFreezesInterpolation = false; //!< paused simulator will also pause interpolation (so AI aircraft will hold)
|
||||
|
||||
private:
|
||||
@@ -152,7 +153,7 @@ namespace BlackCore
|
||||
BlackMisc::Aviation::CCallsignSet m_callsignsToBeRendered; //!< callsigns which will be rendered
|
||||
int m_maxRenderedAircraft = MaxAircraftInfinite; //!< max.rendered aircraft
|
||||
BlackMisc::PhysicalQuantities::CLength m_maxRenderedDistance { 0.0, BlackMisc::PhysicalQuantities::CLengthUnit::nullUnit()}; //!< max.distance for rendering
|
||||
QList<QMetaObject::Connection> m_remoteAircraftProviderConnections; //!< connected signal/slots
|
||||
BlackMisc::CConnectionGuard m_remoteAircraftProviderConnections; //!< connected signal/slots
|
||||
};
|
||||
} // namespace
|
||||
|
||||
|
||||
Reference in New Issue
Block a user