Skip to content

Commit b7aa717

Browse files
committed
refactor: gui, simplify boost signals disconnection
Preventing dangling signals.
1 parent f3a612f commit b7aa717

File tree

2 files changed

+16
-28
lines changed

2 files changed

+16
-28
lines changed

src/qt/clientmodel.cpp

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -243,47 +243,41 @@ void ClientModel::TipChanged(SynchronizationState sync_state, interfaces::BlockT
243243

244244
void ClientModel::subscribeToCoreSignals()
245245
{
246-
m_handler_show_progress = m_node.handleShowProgress(
246+
m_event_handlers.emplace_back(m_node.handleShowProgress(
247247
[this](const std::string& title, int progress, [[maybe_unused]] bool resume_possible) {
248248
Q_EMIT showProgress(QString::fromStdString(title), progress);
249-
});
250-
m_handler_notify_num_connections_changed = m_node.handleNotifyNumConnectionsChanged(
249+
}));
250+
m_event_handlers.emplace_back(m_node.handleNotifyNumConnectionsChanged(
251251
[this](int new_num_connections) {
252252
Q_EMIT numConnectionsChanged(new_num_connections);
253-
});
254-
m_handler_notify_network_active_changed = m_node.handleNotifyNetworkActiveChanged(
253+
}));
254+
m_event_handlers.emplace_back(m_node.handleNotifyNetworkActiveChanged(
255255
[this](bool network_active) {
256256
Q_EMIT networkActiveChanged(network_active);
257-
});
258-
m_handler_notify_alert_changed = m_node.handleNotifyAlertChanged(
257+
}));
258+
m_event_handlers.emplace_back(m_node.handleNotifyAlertChanged(
259259
[this]() {
260260
qDebug() << "ClientModel: NotifyAlertChanged";
261261
Q_EMIT alertsChanged(getStatusBarWarnings());
262-
});
263-
m_handler_banned_list_changed = m_node.handleBannedListChanged(
262+
}));
263+
m_event_handlers.emplace_back(m_node.handleBannedListChanged(
264264
[this]() {
265265
qDebug() << "ClienModel: Requesting update for peer banlist";
266266
QMetaObject::invokeMethod(banTableModel, [this] { banTableModel->refresh(); });
267-
});
268-
m_handler_notify_block_tip = m_node.handleNotifyBlockTip(
267+
}));
268+
m_event_handlers.emplace_back(m_node.handleNotifyBlockTip(
269269
[this](SynchronizationState sync_state, interfaces::BlockTip tip, double verification_progress) {
270270
TipChanged(sync_state, tip, verification_progress, SyncType::BLOCK_SYNC);
271-
});
272-
m_handler_notify_header_tip = m_node.handleNotifyHeaderTip(
271+
}));
272+
m_event_handlers.emplace_back(m_node.handleNotifyHeaderTip(
273273
[this](SynchronizationState sync_state, interfaces::BlockTip tip, bool presync) {
274274
TipChanged(sync_state, tip, /*verification_progress=*/0.0, presync ? SyncType::HEADER_PRESYNC : SyncType::HEADER_SYNC);
275-
});
275+
}));
276276
}
277277

278278
void ClientModel::unsubscribeFromCoreSignals()
279279
{
280-
m_handler_show_progress->disconnect();
281-
m_handler_notify_num_connections_changed->disconnect();
282-
m_handler_notify_network_active_changed->disconnect();
283-
m_handler_notify_alert_changed->disconnect();
284-
m_handler_banned_list_changed->disconnect();
285-
m_handler_notify_block_tip->disconnect();
286-
m_handler_notify_header_tip->disconnect();
280+
m_event_handlers.clear();
287281
}
288282

289283
bool ClientModel::getProxyInfo(std::string& ip_port) const

src/qt/clientmodel.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,7 @@ class ClientModel : public QObject
9797

9898
private:
9999
interfaces::Node& m_node;
100-
std::unique_ptr<interfaces::Handler> m_handler_show_progress;
101-
std::unique_ptr<interfaces::Handler> m_handler_notify_num_connections_changed;
102-
std::unique_ptr<interfaces::Handler> m_handler_notify_network_active_changed;
103-
std::unique_ptr<interfaces::Handler> m_handler_notify_alert_changed;
104-
std::unique_ptr<interfaces::Handler> m_handler_banned_list_changed;
105-
std::unique_ptr<interfaces::Handler> m_handler_notify_block_tip;
106-
std::unique_ptr<interfaces::Handler> m_handler_notify_header_tip;
100+
std::vector<std::unique_ptr<interfaces::Handler>> m_event_handlers;
107101
OptionsModel *optionsModel;
108102
PeerTableModel* peerTableModel{nullptr};
109103
PeerTableSortProxy* m_peer_table_sort_proxy{nullptr};

0 commit comments

Comments
 (0)