Skip to content

Commit 8963b2c

Browse files
committed
qt: Improve comments in WalletController::getOrCreateWallet()
1 parent 5fcfee6 commit 8963b2c

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/qt/walletcontroller.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,14 @@ WalletModel* WalletController::getOrCreateWallet(std::unique_ptr<interfaces::Wal
128128
}
129129

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

164-
// Notify walletAdded signal on the GUI thread.
165170
Q_EMIT walletAdded(wallet_model);
166171

167172
return wallet_model;

0 commit comments

Comments
 (0)