@@ -128,8 +128,14 @@ WalletModel* WalletController::getOrCreateWallet(std::unique_ptr<interfaces::Wal
128
128
}
129
129
130
130
// 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.
133
139
wallet_model->moveToThread (thread ());
134
140
// setParent(parent) must be called in the thread which created the parent object. More details in #18948.
135
141
GUIUtil::ObjectInvoke (this , [wallet_model, this ] {
@@ -161,7 +167,6 @@ WalletModel* WalletController::getOrCreateWallet(std::unique_ptr<interfaces::Wal
161
167
// Re-emit coinsSent signal from wallet model.
162
168
connect (wallet_model, &WalletModel::coinsSent, this , &WalletController::coinsSent);
163
169
164
- // Notify walletAdded signal on the GUI thread.
165
170
Q_EMIT walletAdded (wallet_model);
166
171
167
172
return wallet_model;
0 commit comments