refactor: gui, simplify boost signals disconnection

Preventing dangling signals.
This commit is contained in:
furszy 2024-02-28 09:57:49 -03:00
parent f3a612f901
commit b7aa717cdd
No known key found for this signature in database
GPG key ID: 5DD23CCC686AA623
2 changed files with 16 additions and 28 deletions

View file

@ -243,47 +243,41 @@ void ClientModel::TipChanged(SynchronizationState sync_state, interfaces::BlockT
void ClientModel::subscribeToCoreSignals() void ClientModel::subscribeToCoreSignals()
{ {
m_handler_show_progress = m_node.handleShowProgress( m_event_handlers.emplace_back(m_node.handleShowProgress(
[this](const std::string& title, int progress, [[maybe_unused]] bool resume_possible) { [this](const std::string& title, int progress, [[maybe_unused]] bool resume_possible) {
Q_EMIT showProgress(QString::fromStdString(title), progress); Q_EMIT showProgress(QString::fromStdString(title), progress);
}); }));
m_handler_notify_num_connections_changed = m_node.handleNotifyNumConnectionsChanged( m_event_handlers.emplace_back(m_node.handleNotifyNumConnectionsChanged(
[this](int new_num_connections) { [this](int new_num_connections) {
Q_EMIT numConnectionsChanged(new_num_connections); Q_EMIT numConnectionsChanged(new_num_connections);
}); }));
m_handler_notify_network_active_changed = m_node.handleNotifyNetworkActiveChanged( m_event_handlers.emplace_back(m_node.handleNotifyNetworkActiveChanged(
[this](bool network_active) { [this](bool network_active) {
Q_EMIT networkActiveChanged(network_active); Q_EMIT networkActiveChanged(network_active);
}); }));
m_handler_notify_alert_changed = m_node.handleNotifyAlertChanged( m_event_handlers.emplace_back(m_node.handleNotifyAlertChanged(
[this]() { [this]() {
qDebug() << "ClientModel: NotifyAlertChanged"; qDebug() << "ClientModel: NotifyAlertChanged";
Q_EMIT alertsChanged(getStatusBarWarnings()); Q_EMIT alertsChanged(getStatusBarWarnings());
}); }));
m_handler_banned_list_changed = m_node.handleBannedListChanged( m_event_handlers.emplace_back(m_node.handleBannedListChanged(
[this]() { [this]() {
qDebug() << "ClienModel: Requesting update for peer banlist"; qDebug() << "ClienModel: Requesting update for peer banlist";
QMetaObject::invokeMethod(banTableModel, [this] { banTableModel->refresh(); }); QMetaObject::invokeMethod(banTableModel, [this] { banTableModel->refresh(); });
}); }));
m_handler_notify_block_tip = m_node.handleNotifyBlockTip( m_event_handlers.emplace_back(m_node.handleNotifyBlockTip(
[this](SynchronizationState sync_state, interfaces::BlockTip tip, double verification_progress) { [this](SynchronizationState sync_state, interfaces::BlockTip tip, double verification_progress) {
TipChanged(sync_state, tip, verification_progress, SyncType::BLOCK_SYNC); TipChanged(sync_state, tip, verification_progress, SyncType::BLOCK_SYNC);
}); }));
m_handler_notify_header_tip = m_node.handleNotifyHeaderTip( m_event_handlers.emplace_back(m_node.handleNotifyHeaderTip(
[this](SynchronizationState sync_state, interfaces::BlockTip tip, bool presync) { [this](SynchronizationState sync_state, interfaces::BlockTip tip, bool presync) {
TipChanged(sync_state, tip, /*verification_progress=*/0.0, presync ? SyncType::HEADER_PRESYNC : SyncType::HEADER_SYNC); TipChanged(sync_state, tip, /*verification_progress=*/0.0, presync ? SyncType::HEADER_PRESYNC : SyncType::HEADER_SYNC);
}); }));
} }
void ClientModel::unsubscribeFromCoreSignals() void ClientModel::unsubscribeFromCoreSignals()
{ {
m_handler_show_progress->disconnect(); m_event_handlers.clear();
m_handler_notify_num_connections_changed->disconnect();
m_handler_notify_network_active_changed->disconnect();
m_handler_notify_alert_changed->disconnect();
m_handler_banned_list_changed->disconnect();
m_handler_notify_block_tip->disconnect();
m_handler_notify_header_tip->disconnect();
} }
bool ClientModel::getProxyInfo(std::string& ip_port) const bool ClientModel::getProxyInfo(std::string& ip_port) const

View file

@ -97,13 +97,7 @@ public:
private: private:
interfaces::Node& m_node; interfaces::Node& m_node;
std::unique_ptr<interfaces::Handler> m_handler_show_progress; std::vector<std::unique_ptr<interfaces::Handler>> m_event_handlers;
std::unique_ptr<interfaces::Handler> m_handler_notify_num_connections_changed;
std::unique_ptr<interfaces::Handler> m_handler_notify_network_active_changed;
std::unique_ptr<interfaces::Handler> m_handler_notify_alert_changed;
std::unique_ptr<interfaces::Handler> m_handler_banned_list_changed;
std::unique_ptr<interfaces::Handler> m_handler_notify_block_tip;
std::unique_ptr<interfaces::Handler> m_handler_notify_header_tip;
OptionsModel *optionsModel; OptionsModel *optionsModel;
PeerTableModel* peerTableModel{nullptr}; PeerTableModel* peerTableModel{nullptr};
PeerTableSortProxy* m_peer_table_sort_proxy{nullptr}; PeerTableSortProxy* m_peer_table_sort_proxy{nullptr};