Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
251error.translated += tr("Settings file %1 might be corrupt or invalid.").arg(QString::fromStdString(quoted_path)).toStdString();252}253InitError(error);254QMessageBox::critical(nullptr, CLIENT_NAME, QString::fromStdString(error.translated));255return false;256}257return true;258}260void BitcoinApplication::createWindow(const NetworkStyle *networkStyle)261{262window = new BitcoinGUI(node(), platformStyle, networkStyle, nullptr);263connect(window, &BitcoinGUI::quitRequested, this, &BitcoinApplication::requestShutdown);265pollShutdownTimer = new QTimer(window);266connect(pollShutdownTimer, &QTimer::timeout, [this]{267if (!QApplication::activeModalWidget()) {268window->detectShutdown();269}270});271}273void BitcoinApplication::createSplashScreen(const NetworkStyle *networkStyle)274{275assert(!m_splash);276m_splash = new SplashScreen(networkStyle);277m_splash->show();278}280void BitcoinApplication::createNode(interfaces::Init& init)281{282assert(!m_node);283m_node = init.makeNode();284if (m_splash) m_splash->setNode(*m_node);285}287bool BitcoinApplication::baseInitialize()288{289return node().baseInitialize();290}292void BitcoinApplication::startThread()293{294assert(!m_executor);295m_executor.emplace(node());297/* communication to and from thread */298connect(&m_executor.value(), &InitExecutor::initializeResult, this, &BitcoinApplication::initializeResult);299connect(&m_executor.value(), &InitExecutor::shutdownResult, this, [] {300QCoreApplication::exit(0);301});302connect(&m_executor.value(), &InitExecutor::runawayException, this, &BitcoinApplication::handleRunawayException);303connect(this, &BitcoinApplication::requestedInitialize, &m_executor.value(), &InitExecutor::initialize);304connect(this, &BitcoinApplication::requestedShutdown, &m_executor.value(), &InitExecutor::shutdown);305}307void BitcoinApplication::parameterSetup()308{309// Default printtoconsole to false for the GUI. GUI programs should not310// print to the console unnecessarily.311gArgs.SoftSetBoolArg("-printtoconsole", false);313InitLogging(gArgs);314InitParameterInteraction(gArgs);315}317void BitcoinApplication::InitPruneSetting(int64_t prune_MiB)318{319optionsModel->SetPruneTargetGB(PruneMiBtoGB(prune_MiB));320}322void BitcoinApplication::requestInitialize()323{324qDebug() << __func__ << ": Requesting initialize";325startThread();326Q_EMIT requestedInitialize();327}329void BitcoinApplication::requestShutdown()330{331for (const auto w : QGuiApplication::topLevelWindows()) {332w->hide();333}335delete m_splash;336m_splash = nullptr;338// Show a simple window indicating shutdown status339// Do this first as some of the steps may take some time below,340// for example the RPC console may still be executing a command.341shutdownWindow.reset(ShutdownWindow::showShutdownWindow(window));343qDebug() << __func__ << ": Requesting shutdown";345// Must disconnect node signals otherwise current thread can deadlock since346// no event loop is running.347window->unsubscribeFromCoreSignals();348// Request node shutdown, which can interrupt long operations, like349// rescanning a wallet.350node().startShutdown();351// Prior to unsetting the client model, stop listening backend signals352if (clientModel) {353clientModel->stop();354}356// Unsetting the client model can cause the current thread to wait for node357// to complete an operation, like wait for a RPC execution to complete.358window->setClientModel(nullptr);359pollShutdownTimer->stop();361#ifdef ENABLE_WALLET362// Delete wallet controller here manually, instead of relying on Qt object363// tracking (https://doc.qt.io/qt-5/objecttrees.html). This makes sure364// walletmodel m_handle_* notification handlers are deleted before wallets365// are unloaded, which can simplify wallet implementations. It also avoids366// these notifications having to be handled while GUI objects are being367// destroyed, making GUI code less fragile as well.368delete m_wallet_controller;369m_wallet_controller = nullptr;370#endif // ENABLE_WALLET372delete clientModel;373clientModel = nullptr;375// Request shutdown from core thread376Q_EMIT requestedShutdown();377}379void BitcoinApplication::initializeResult(bool success, interfaces::BlockAndHeaderTipInfo tip_info)380{381qDebug() << __func__ << ": Initialization result: " << success;383if (!success || m_node->shutdownRequested()) {384requestShutdown();385return;386}388delete m_splash;389m_splash = nullptr;391// Log this only after AppInitMain finishes, as then logging setup is guaranteed complete392qInfo() << "Platform customization:" << platformStyle->getName();393clientModel = new ClientModel(node(), optionsModel);394window->setClientModel(clientModel, &tip_info);396// If '-min' option passed, start window minimized (iconified) or minimized to tray397bool start_minimized = gArgs.GetBoolArg("-min", false);398#ifdef ENABLE_WALLET399if (WalletModel::isWalletEnabled()) {400m_wallet_controller = new WalletController(*clientModel, platformStyle, this);401window->setWalletController(m_wallet_controller, /*show_loading_minimized=*/start_minimized);402if (paymentServer) {403paymentServer->setOptionsModel(optionsModel);404}405}406#endif // ENABLE_WALLET408// Show or minimize window409if (!start_minimized) {410window->show();411} else if (clientModel->getOptionsModel()->getMinimizeToTray() && window->hasTrayIcon()) {412// do nothing as the window is managed by the tray icon413} else {414window->showMinimized();415}416Q_EMIT windowShown(window);418#ifdef ENABLE_WALLET419// Now that initialization/startup is done, process any command-line420// bitcoin: URIs or payment requests:421if (paymentServer) {422connect(paymentServer, &PaymentServer::receivedPaymentRequest, window, &BitcoinGUI::handlePaymentRequest);423connect(window, &BitcoinGUI::receivedURI, paymentServer, &PaymentServer::handleURIOrFile);424connect(paymentServer, &PaymentServer::message, [this](const QString& title, const QString& message, unsigned int style) {425window->message(title, message, style);426});427QTimer::singleShot(100ms, paymentServer, &PaymentServer::uiReady);428}429#endif430pollShutdownTimer->start(SHUTDOWN_POLLING_DELAY);431}433void BitcoinApplication::handleRunawayException(const QString &message)434{435QMessageBox::critical(436nullptr, tr("Runaway exception"),437tr("A fatal error occurred. %1 can no longer continue safely and will quit.").arg(CLIENT_NAME) +438QLatin1String("<br><br>") + GUIUtil::MakeHtmlLink(message, CLIENT_BUGREPORT));439::exit(EXIT_FAILURE);440}442void BitcoinApplication::handleNonFatalException(const QString& message)443{444assert(QThread::currentThread() == thread());445QMessageBox::warning(446nullptr, tr("Internal error"),447tr("An internal error occurred. %1 will attempt to continue safely. This is "448"an unexpected bug which can be reported as described below.").arg(CLIENT_NAME) +449QLatin1String("<br><br>") + GUIUtil::MakeHtmlLink(message, CLIENT_BUGREPORT));450}452WId BitcoinApplication::getMainWinId() const453{454if (!window)455return 0;457return window->winId();458}460bool BitcoinApplication::event(QEvent* e)461{462if (e->type() == QEvent::Quit) {463requestShutdown();464return true;465}467return QApplication::event(e);468}470static void SetupUIArgs(ArgsManager& argsman)471{472argsman.AddArg("-choosedatadir", strprintf("Choose data directory on startup (default: %u)", DEFAULT_CHOOSE_DATADIR), ArgsManager::ALLOW_ANY, OptionsCategory::GUI);473argsman.AddArg("-lang=<lang>", "Set language, for example \"de_DE\" (default: system locale)", ArgsManager::ALLOW_ANY, OptionsCategory::GUI);474argsman.AddArg("-min", "Start minimized", ArgsManager::ALLOW_ANY, OptionsCategory::GUI);475argsman.AddArg("-resetguisettings", "Reset all settings changed in the GUI", ArgsManager::ALLOW_ANY, OptionsCategory::GUI);476argsman.AddArg("-splash", strprintf("Show splash screen on startup (default: %u)", DEFAULT_SPLASHSCREEN), ArgsManager::ALLOW_ANY, OptionsCategory::GUI);477argsman.AddArg("-uiplatform", strprintf("Select platform to customize UI for (one of windows, macosx, other; default: %s)", BitcoinGUI::DEFAULT_UIPLATFORM), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::GUI);478}480int GuiMain(int argc, char* argv[])481{482std::unique_ptr<interfaces::Init> init = interfaces::MakeGuiInit(argc, argv);484SetupEnvironment();485util::ThreadSetInternalName("main");487// Subscribe to global signals from core488btcsignals::scoped_connection handler_message_box{::uiInterface.ThreadSafeMessageBox.connect(noui_ThreadSafeMessageBox)};489btcsignals::scoped_connection handler_question{::uiInterface.ThreadSafeQuestion.connect(noui_ThreadSafeQuestion)};490btcsignals::scoped_connection handler_init_message{::uiInterface.InitMessage.connect(noui_InitMessage)};492// Do not refer to data directory yet, this can be overridden by Intro::pickDataDirectory494/// 1. Basic Qt initialization (not dependent on parameters or configuration)495Q_INIT_RESOURCE(bitcoin);496Q_INIT_RESOURCE(bitcoin_locale);498#if defined(QT_QPA_PLATFORM_ANDROID)499QApplication::setAttribute(Qt::AA_DontUseNativeMenuBar);500QApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.