| 327 | } |
| 328 | |
| 329 | void BitcoinApplication::requestShutdown() |
| 330 | { |
| 331 | for (const auto w : QGuiApplication::topLevelWindows()) { |
| 332 | w->hide(); |
| 333 | } |
| 334 | |
| 335 | // Show a simple window indicating shutdown status |
| 336 | // Do this first as some of the steps may take some time below, |
| 337 | // for example the RPC console may still be executing a command. |
| 338 | shutdownWindow.reset(ShutdownWindow::showShutdownWindow(window)); |
| 339 | |
| 340 | qDebug() << __func__ << ": Requesting shutdown"; |
| 341 | |
| 342 | // Must disconnect node signals otherwise current thread can deadlock since |
| 343 | // no event loop is running. |
| 344 | window->unsubscribeFromCoreSignals(); |
| 345 | // Request node shutdown, which can interrupt long operations, like |
| 346 | // rescanning a wallet. |
| 347 | node().startShutdown(); |
| 348 | // Unsetting the client model can cause the current thread to wait for node |
| 349 | // to complete an operation, like wait for a RPC execution to complete. |
| 350 | window->setClientModel(nullptr); |
| 351 | pollShutdownTimer->stop(); |
| 352 | |
| 353 | #ifdef ENABLE_WALLET |
| 354 | // Delete wallet controller here manually, instead of relying on Qt object |
| 355 | // tracking (https://doc.qt.io/qt-5/objecttrees.html). This makes sure |
| 356 | // walletmodel m_handle_* notification handlers are deleted before wallets |
| 357 | // are unloaded, which can simplify wallet implementations. It also avoids |
| 358 | // these notifications having to be handled while GUI objects are being |
| 359 | // destroyed, making GUI code less fragile as well. |
| 360 | delete m_wallet_controller; |
| 361 | m_wallet_controller = nullptr; |
| 362 | #endif // ENABLE_WALLET |
| 363 | |
| 364 | delete clientModel; |
| 365 | clientModel = nullptr; |
| 366 | |
| 367 | // Request shutdown from core thread |
| 368 | Q_EMIT requestedShutdown(); |
| 369 | } |
| 370 | |
| 371 | void BitcoinApplication::initializeResult(bool success, interfaces::BlockAndHeaderTipInfo tip_info) |
| 372 | { |