@@ -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