Skip to content

Commit 9059a6f

Browse files
committed
Merge #16349: qt: Remove redundant WalletController::addWallet slot
6285a31 Remove redundant WalletController::addWallet slot (Hennadii Stepanov) Pull request description: ~~Fix #15453.~~ It is fixed by bitcoin/bitcoin#16348 (comment) The _only_ reason of these lines on master (8c69fae) https://github.com/bitcoin/bitcoin/blob/2679bb8919b5089f8067ccfd94f766747b8df671/src/qt/walletcontroller.cpp#L121-L128 is to `Q_EMIT walletAdded(wallet_model);` in a thread-safe manner; This PR makes this in a line of code: https://github.com/bitcoin/bitcoin/blob/1b83875006749d79916af0197bed65aecdc7ff17/src/qt/walletcontroller.cpp#L121 EDITED: To establish the ownership of a new `WalletModel` object is not necessary on the master (bitcoin/bitcoin#16349 (comment) by **promag**). But: > it's good habit to set ownership And I agree. It is a safe practice. ACKs for top commit: promag: ACK 6285a31. jonasschnelli: utACK 6285a31 ryanofsky: utACK 6285a31. Only change since last review is rebasing and restoring a deleted comment. I do think the comments I suggested last review would be better than this one, but this is at least better than before. Tree-SHA512: 90370cb1fe853b84dd16c3781ba4f97f3f4deca56bba0203e457f37b3220fd13228cf8495fd882ff18b7c782c27544cc2e7a88aaec5b69b9ef6d8626bdaaf332
2 parents ac3e652 + 6285a31 commit 9059a6f

File tree

2 files changed

+4
-18
lines changed

2 files changed

+4
-18
lines changed

src/qt/walletcontroller.cpp

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ WalletModel* WalletController::getOrCreateWallet(std::unique_ptr<interfaces::Wal
9999

100100
// Instantiate model and register it.
101101
WalletModel* wallet_model = new WalletModel(std::move(wallet), m_node, m_platform_style, m_options_model, nullptr);
102+
// Handler callback runs in a different thread so fix wallet model thread affinity.
103+
wallet_model->moveToThread(thread());
104+
wallet_model->setParent(this);
102105
m_wallets.push_back(wallet_model);
103106

104107
connect(wallet_model, &WalletModel::unload, [this, wallet_model] {
@@ -119,25 +122,11 @@ WalletModel* WalletController::getOrCreateWallet(std::unique_ptr<interfaces::Wal
119122
connect(wallet_model, &WalletModel::coinsSent, this, &WalletController::coinsSent);
120123

121124
// Notify walletAdded signal on the GUI thread.
122-
if (QThread::currentThread() == thread()) {
123-
addWallet(wallet_model);
124-
} else {
125-
// Handler callback runs in a different thread so fix wallet model thread affinity.
126-
wallet_model->moveToThread(thread());
127-
bool invoked = QMetaObject::invokeMethod(this, "addWallet", Qt::QueuedConnection, Q_ARG(WalletModel*, wallet_model));
128-
assert(invoked);
129-
}
125+
Q_EMIT walletAdded(wallet_model);
130126

131127
return wallet_model;
132128
}
133129

134-
void WalletController::addWallet(WalletModel* wallet_model)
135-
{
136-
// Take ownership of the wallet model and register it.
137-
wallet_model->setParent(this);
138-
Q_EMIT walletAdded(wallet_model);
139-
}
140-
141130
void WalletController::removeAndDeleteWallet(WalletModel* wallet_model)
142131
{
143132
// Unregister wallet model.

src/qt/walletcontroller.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ class WalletController : public QObject
5050
OpenWalletActivity* openWallet(const std::string& name, QWidget* parent = nullptr);
5151
void closeWallet(WalletModel* wallet_model, QWidget* parent = nullptr);
5252

53-
private Q_SLOTS:
54-
void addWallet(WalletModel* wallet_model);
55-
5653
Q_SIGNALS:
5754
void walletAdded(WalletModel* wallet_model);
5855
void walletRemoved(WalletModel* wallet_model);

0 commit comments

Comments
 (0)