Merge #16231: gui: Fix open wallet menu initialization order

5224be5a3354e1a22ea4d7f0e40aadfccdf67064 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 5224be5a3354e1a22ea4d7f0e40aadfccdf67064, I have tested the code on Bionic with Qt 5.12.4.
  ryanofsky:
    utACK 5224be5a3354e1a22ea4d7f0e40aadfccdf67064. Looks good, fix is simple and makes perfect sense after seeing explanation in https://github.com/bitcoin/bitcoin/pull/16118#issuecomment-503166407. 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 5224be5a3354e1a22ea4d7f0e40aadfccdf67064 Testing included in a comment above. The segfaulting with QT_FATAL_WARNINGS is unrelated to this change.

Tree-SHA512: 97b42493b37b96683058bccf39a0ee93589293d4ba8f0c60aef7f4fb9dd084cc6d5608cd5ef531cadf5e03b1f01627ef96bc2d79f784fb38cb87aa6643183d41
This commit is contained in:
fanquake 2019-06-23 18:39:53 +08:00 committed by pasta
parent 55739dad5a
commit ce9d941767
2 changed files with 7 additions and 5 deletions

View File

@ -430,6 +430,7 @@ void BitcoinGUI::createActions()
m_open_wallet_action = new QAction(tr("Open Wallet"), this);
m_open_wallet_action->setEnabled(false);
m_open_wallet_action->setStatusTip(tr("Open a wallet"));
m_open_wallet_menu = new QMenu(this);
m_close_wallet_action = new QAction(tr("Close Wallet..."), this);
m_close_wallet_action->setStatusTip(tr("Close wallet"));
@ -482,13 +483,13 @@ void BitcoinGUI::createActions()
connect(usedSendingAddressesAction, &QAction::triggered, walletFrame, &WalletFrame::usedSendingAddresses);
connect(usedReceivingAddressesAction, &QAction::triggered, walletFrame, &WalletFrame::usedReceivingAddresses);
connect(openAction, &QAction::triggered, this, &BitcoinGUI::openClicked);
connect(m_open_wallet_action->menu(), &QMenu::aboutToShow, [this] {
m_open_wallet_action->menu()->clear();
connect(m_open_wallet_menu, &QMenu::aboutToShow, [this] {
m_open_wallet_menu->clear();
std::vector<std::string> available_wallets = m_wallet_controller->getWalletsAvailableToOpen();
std::vector<std::string> wallets = m_node.listWalletDir();
for (const auto& path : wallets) {
QString name = path.empty() ? QString("["+tr("default wallet")+"]") : QString::fromStdString(path);
QAction* action = m_open_wallet_action->menu()->addAction(name);
QAction* action = m_open_wallet_menu->addAction(name);
if (std::find(available_wallets.begin(), available_wallets.end(), path) == available_wallets.end()) {
// This wallet is already loaded
@ -524,7 +525,7 @@ void BitcoinGUI::createActions()
});
}
if (wallets.empty()) {
QAction* action = m_open_wallet_action->menu()->addAction(tr("No wallets available"));
QAction* action = m_open_wallet_menu->addAction(tr("No wallets available"));
action->setEnabled(false);
}
});
@ -857,7 +858,7 @@ void BitcoinGUI::setWalletController(WalletController* wallet_controller)
m_wallet_controller = wallet_controller;
m_open_wallet_action->setEnabled(true);
m_open_wallet_action->setMenu(new QMenu(this));
m_open_wallet_action->setMenu(m_open_wallet_menu);
connect(wallet_controller, &WalletController::walletAdded, this, &BitcoinGUI::addWallet);
connect(wallet_controller, &WalletController::walletRemoved, this, &BitcoinGUI::removeWallet);

View File

@ -160,6 +160,7 @@ private:
QAction* openAction = nullptr;
QAction* showHelpMessageAction = nullptr;
QAction* m_open_wallet_action{nullptr};
QMenu* m_open_wallet_menu{nullptr};
QAction* m_close_wallet_action{nullptr};
QAction* showCoinJoinHelpAction = nullptr;
QAction* m_wallet_selector_action = nullptr;