Skip to content

Commit c1bab50

Browse files
committed
Merge #16231: gui: Fix open wallet menu initialization order
5224be5 gui: Fix open wallet menu initialization order (João Barbosa) Pull request description: Fixes #16230, the menu must be created before connecting to aboutToShow signal. ACKs for commit 5224be: hebasto: ACK 5224be5, I have tested the code on Bionic with Qt 5.12.4. ryanofsky: utACK 5224be5. Looks good, fix is simple and makes perfect sense after seeing explanation in bitcoin/bitcoin#16118 (comment). Without this change (and since #16118), the menu pointer passed to `connect(m_open_wallet_action->menu(), ...)` is null and connecting has no effect. With this change, the menu is constructed earlier so the connect call can work. fanquake: ACK 5224be5 Testing included in a comment above. The segfaulting with QT_FATAL_WARNINGS is unrelated to this change. Tree-SHA512: 97b42493b37b96683058bccf39a0ee93589293d4ba8f0c60aef7f4fb9dd084cc6d5608cd5ef531cadf5e03b1f01627ef96bc2d79f784fb38cb87aa6643183d41
2 parents 2cbcc55 + 5224be5 commit c1bab50

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/qt/bitcoingui.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ void BitcoinGUI::createActions()
337337
m_open_wallet_action = new QAction(tr("Open Wallet"), this);
338338
m_open_wallet_action->setEnabled(false);
339339
m_open_wallet_action->setStatusTip(tr("Open a wallet"));
340+
m_open_wallet_menu = new QMenu(this);
340341

341342
m_close_wallet_action = new QAction(tr("Close Wallet..."), this);
342343
m_close_wallet_action->setStatusTip(tr("Close wallet"));
@@ -368,13 +369,13 @@ void BitcoinGUI::createActions()
368369
connect(usedSendingAddressesAction, &QAction::triggered, walletFrame, &WalletFrame::usedSendingAddresses);
369370
connect(usedReceivingAddressesAction, &QAction::triggered, walletFrame, &WalletFrame::usedReceivingAddresses);
370371
connect(openAction, &QAction::triggered, this, &BitcoinGUI::openClicked);
371-
connect(m_open_wallet_action->menu(), &QMenu::aboutToShow, [this] {
372-
m_open_wallet_action->menu()->clear();
372+
connect(m_open_wallet_menu, &QMenu::aboutToShow, [this] {
373+
m_open_wallet_menu->clear();
373374
std::vector<std::string> available_wallets = m_wallet_controller->getWalletsAvailableToOpen();
374375
std::vector<std::string> wallets = m_node.listWalletDir();
375376
for (const auto& path : wallets) {
376377
QString name = path.empty() ? QString("["+tr("default wallet")+"]") : QString::fromStdString(path);
377-
QAction* action = m_open_wallet_action->menu()->addAction(name);
378+
QAction* action = m_open_wallet_menu->addAction(name);
378379

379380
if (std::find(available_wallets.begin(), available_wallets.end(), path) == available_wallets.end()) {
380381
// This wallet is already loaded
@@ -410,7 +411,7 @@ void BitcoinGUI::createActions()
410411
});
411412
}
412413
if (wallets.empty()) {
413-
QAction* action = m_open_wallet_action->menu()->addAction(tr("No wallets available"));
414+
QAction* action = m_open_wallet_menu->addAction(tr("No wallets available"));
414415
action->setEnabled(false);
415416
}
416417
});
@@ -634,7 +635,7 @@ void BitcoinGUI::setWalletController(WalletController* wallet_controller)
634635
m_wallet_controller = wallet_controller;
635636

636637
m_open_wallet_action->setEnabled(true);
637-
m_open_wallet_action->setMenu(new QMenu(this));
638+
m_open_wallet_action->setMenu(m_open_wallet_menu);
638639

639640
connect(wallet_controller, &WalletController::walletAdded, this, &BitcoinGUI::addWallet);
640641
connect(wallet_controller, &WalletController::walletRemoved, this, &BitcoinGUI::removeWallet);

src/qt/bitcoingui.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ class BitcoinGUI : public QMainWindow
148148
QAction* openAction = nullptr;
149149
QAction* showHelpMessageAction = nullptr;
150150
QAction* m_open_wallet_action{nullptr};
151+
QMenu* m_open_wallet_menu{nullptr};
151152
QAction* m_close_wallet_action{nullptr};
152153
QAction* m_wallet_selector_label_action = nullptr;
153154
QAction* m_wallet_selector_action = nullptr;

0 commit comments

Comments
 (0)