Skip to content

Commit 34b83a1

Browse files
committed
qt: Improve comments in WalletController::getOrCreateWallet()
1 parent e92e600 commit 34b83a1

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/qt/walletcontroller.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,14 @@ WalletModel* WalletController::getOrCreateWallet(std::unique_ptr<interfaces::Wal
124124
}
125125

126126
// Instantiate model and register it.
127-
WalletModel* wallet_model = new WalletModel(std::move(wallet), m_client_model, m_platform_style, nullptr);
128-
// Handler callback runs in a different thread so fix wallet model thread affinity.
127+
WalletModel* wallet_model = new WalletModel(std::move(wallet), m_client_model, m_platform_style,
128+
nullptr /* required for the following moveToThread() call */);
129+
130+
// Move WalletModel object to the thread that created the WalletController
131+
// object (GUI main thread), instead of the current thread, which could be
132+
// an outside wallet thread or RPC thread sending a LoadWallet notification.
133+
// This ensures queued signals sent to the WalletModel object will be
134+
// handled on the GUI event loop.
129135
wallet_model->moveToThread(thread());
130136
// setParent(parent) must be called in the thread which created the parent object. More details in #18948.
131137
GUIUtil::ObjectInvoke(this, [wallet_model, this] {
@@ -157,7 +163,6 @@ WalletModel* WalletController::getOrCreateWallet(std::unique_ptr<interfaces::Wal
157163
// Re-emit coinsSent signal from wallet model.
158164
connect(wallet_model, &WalletModel::coinsSent, this, &WalletController::coinsSent);
159165

160-
// Notify walletAdded signal on the GUI thread.
161166
Q_EMIT walletAdded(wallet_model);
162167

163168
return wallet_model;

0 commit comments

Comments
 (0)