mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-26 11:13:23 -03:00
qt: Do not exit and re-enter main event loop during shutdown
This commit is contained in:
parent
b4e0d2c431
commit
f3a17bbe5f
6 changed files with 19 additions and 11 deletions
|
@ -54,6 +54,7 @@
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QTranslator>
|
#include <QTranslator>
|
||||||
|
#include <QWindow>
|
||||||
|
|
||||||
#if defined(QT_STATICPLUGIN)
|
#if defined(QT_STATICPLUGIN)
|
||||||
#include <QtPlugin>
|
#include <QtPlugin>
|
||||||
|
@ -258,6 +259,7 @@ void BitcoinApplication::createOptionsModel(bool resetSettings)
|
||||||
void BitcoinApplication::createWindow(const NetworkStyle *networkStyle)
|
void BitcoinApplication::createWindow(const NetworkStyle *networkStyle)
|
||||||
{
|
{
|
||||||
window = new BitcoinGUI(node(), platformStyle, networkStyle, nullptr);
|
window = new BitcoinGUI(node(), platformStyle, networkStyle, nullptr);
|
||||||
|
connect(window, &BitcoinGUI::quitRequested, this, &BitcoinApplication::requestShutdown);
|
||||||
|
|
||||||
pollShutdownTimer = new QTimer(window);
|
pollShutdownTimer = new QTimer(window);
|
||||||
connect(pollShutdownTimer, &QTimer::timeout, window, &BitcoinGUI::detectShutdown);
|
connect(pollShutdownTimer, &QTimer::timeout, window, &BitcoinGUI::detectShutdown);
|
||||||
|
@ -325,13 +327,17 @@ void BitcoinApplication::requestInitialize()
|
||||||
|
|
||||||
void BitcoinApplication::requestShutdown()
|
void BitcoinApplication::requestShutdown()
|
||||||
{
|
{
|
||||||
|
for (const auto w : QGuiApplication::topLevelWindows()) {
|
||||||
|
w->hide();
|
||||||
|
}
|
||||||
|
|
||||||
// Show a simple window indicating shutdown status
|
// Show a simple window indicating shutdown status
|
||||||
// Do this first as some of the steps may take some time below,
|
// Do this first as some of the steps may take some time below,
|
||||||
// for example the RPC console may still be executing a command.
|
// for example the RPC console may still be executing a command.
|
||||||
shutdownWindow.reset(ShutdownWindow::showShutdownWindow(window));
|
shutdownWindow.reset(ShutdownWindow::showShutdownWindow(window));
|
||||||
|
|
||||||
qDebug() << __func__ << ": Requesting shutdown";
|
qDebug() << __func__ << ": Requesting shutdown";
|
||||||
window->hide();
|
|
||||||
// Must disconnect node signals otherwise current thread can deadlock since
|
// Must disconnect node signals otherwise current thread can deadlock since
|
||||||
// no event loop is running.
|
// no event loop is running.
|
||||||
window->unsubscribeFromCoreSignals();
|
window->unsubscribeFromCoreSignals();
|
||||||
|
@ -408,13 +414,13 @@ void BitcoinApplication::initializeResult(bool success, interfaces::BlockAndHead
|
||||||
pollShutdownTimer->start(200);
|
pollShutdownTimer->start(200);
|
||||||
} else {
|
} else {
|
||||||
Q_EMIT splashFinished(); // Make sure splash screen doesn't stick around during shutdown
|
Q_EMIT splashFinished(); // Make sure splash screen doesn't stick around during shutdown
|
||||||
quit(); // Exit first main loop invocation
|
requestShutdown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BitcoinApplication::shutdownResult()
|
void BitcoinApplication::shutdownResult()
|
||||||
{
|
{
|
||||||
quit(); // Exit second main loop invocation after shutdown finished
|
quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BitcoinApplication::handleRunawayException(const QString &message)
|
void BitcoinApplication::handleRunawayException(const QString &message)
|
||||||
|
@ -637,8 +643,6 @@ int GuiMain(int argc, char* argv[])
|
||||||
#if defined(Q_OS_WIN)
|
#if defined(Q_OS_WIN)
|
||||||
WinShutdownMonitor::registerShutdownBlockReason(QObject::tr("%1 didn't yet exit safely…").arg(PACKAGE_NAME), (HWND)app.getMainWinId());
|
WinShutdownMonitor::registerShutdownBlockReason(QObject::tr("%1 didn't yet exit safely…").arg(PACKAGE_NAME), (HWND)app.getMainWinId());
|
||||||
#endif
|
#endif
|
||||||
app.exec();
|
|
||||||
app.requestShutdown();
|
|
||||||
app.exec();
|
app.exec();
|
||||||
rv = app.getReturnValue();
|
rv = app.getReturnValue();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -56,8 +56,6 @@ public:
|
||||||
|
|
||||||
/// Request core initialization
|
/// Request core initialization
|
||||||
void requestInitialize();
|
void requestInitialize();
|
||||||
/// Request core shutdown
|
|
||||||
void requestShutdown();
|
|
||||||
|
|
||||||
/// Get process return value
|
/// Get process return value
|
||||||
int getReturnValue() const { return returnValue; }
|
int getReturnValue() const { return returnValue; }
|
||||||
|
@ -73,6 +71,8 @@ public:
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void initializeResult(bool success, interfaces::BlockAndHeaderTipInfo tip_info);
|
void initializeResult(bool success, interfaces::BlockAndHeaderTipInfo tip_info);
|
||||||
|
/// Request core shutdown
|
||||||
|
void requestShutdown();
|
||||||
void shutdownResult();
|
void shutdownResult();
|
||||||
/// Handle runaway exceptions. Shows a message box with the problem and quits the program.
|
/// Handle runaway exceptions. Shows a message box with the problem and quits the program.
|
||||||
void handleRunawayException(const QString &message);
|
void handleRunawayException(const QString &message);
|
||||||
|
|
|
@ -371,7 +371,7 @@ void BitcoinGUI::createActions()
|
||||||
m_mask_values_action->setStatusTip(tr("Mask the values in the Overview tab"));
|
m_mask_values_action->setStatusTip(tr("Mask the values in the Overview tab"));
|
||||||
m_mask_values_action->setCheckable(true);
|
m_mask_values_action->setCheckable(true);
|
||||||
|
|
||||||
connect(quitAction, &QAction::triggered, qApp, QApplication::quit);
|
connect(quitAction, &QAction::triggered, this, &BitcoinGUI::quitRequested);
|
||||||
connect(aboutAction, &QAction::triggered, this, &BitcoinGUI::aboutClicked);
|
connect(aboutAction, &QAction::triggered, this, &BitcoinGUI::aboutClicked);
|
||||||
connect(aboutQtAction, &QAction::triggered, qApp, QApplication::aboutQt);
|
connect(aboutQtAction, &QAction::triggered, qApp, QApplication::aboutQt);
|
||||||
connect(optionsAction, &QAction::triggered, this, &BitcoinGUI::optionsClicked);
|
connect(optionsAction, &QAction::triggered, this, &BitcoinGUI::optionsClicked);
|
||||||
|
@ -991,6 +991,7 @@ void BitcoinGUI::openOptionsDialogWithTab(OptionsDialog::Tab tab)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto dlg = new OptionsDialog(this, enableWallet);
|
auto dlg = new OptionsDialog(this, enableWallet);
|
||||||
|
connect(dlg, &OptionsDialog::quitOnReset, this, &BitcoinGUI::quitRequested);
|
||||||
dlg->setCurrentTab(tab);
|
dlg->setCurrentTab(tab);
|
||||||
dlg->setModel(clientModel->getOptionsModel());
|
dlg->setModel(clientModel->getOptionsModel());
|
||||||
GUIUtil::ShowModalDialogAndDeleteOnClose(dlg);
|
GUIUtil::ShowModalDialogAndDeleteOnClose(dlg);
|
||||||
|
@ -1216,7 +1217,7 @@ void BitcoinGUI::closeEvent(QCloseEvent *event)
|
||||||
// close rpcConsole in case it was open to make some space for the shutdown window
|
// close rpcConsole in case it was open to make some space for the shutdown window
|
||||||
rpcConsole->close();
|
rpcConsole->close();
|
||||||
|
|
||||||
QApplication::quit();
|
Q_EMIT quitRequested();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1410,7 +1411,7 @@ void BitcoinGUI::detectShutdown()
|
||||||
{
|
{
|
||||||
if(rpcConsole)
|
if(rpcConsole)
|
||||||
rpcConsole->hide();
|
rpcConsole->hide();
|
||||||
qApp->quit();
|
Q_EMIT quitRequested();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -214,6 +214,7 @@ private:
|
||||||
void openOptionsDialogWithTab(OptionsDialog::Tab tab);
|
void openOptionsDialogWithTab(OptionsDialog::Tab tab);
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
|
void quitRequested();
|
||||||
/** Signal raised when a URI was entered or dragged to the GUI */
|
/** Signal raised when a URI was entered or dragged to the GUI */
|
||||||
void receivedURI(const QString &uri);
|
void receivedURI(const QString &uri);
|
||||||
/** Signal raised when RPC console shown */
|
/** Signal raised when RPC console shown */
|
||||||
|
|
|
@ -290,7 +290,8 @@ void OptionsDialog::on_resetButton_clicked()
|
||||||
|
|
||||||
/* reset all options and close GUI */
|
/* reset all options and close GUI */
|
||||||
model->Reset();
|
model->Reset();
|
||||||
QApplication::quit();
|
close();
|
||||||
|
Q_EMIT quitOnReset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,6 +68,7 @@ private Q_SLOTS:
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void proxyIpChecks(QValidatedLineEdit *pUiProxyIp, uint16_t nProxyPort);
|
void proxyIpChecks(QValidatedLineEdit *pUiProxyIp, uint16_t nProxyPort);
|
||||||
|
void quitOnReset();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::OptionsDialog *ui;
|
Ui::OptionsDialog *ui;
|
||||||
|
|
Loading…
Add table
Reference in a new issue