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.
1// Copyright (c) 2011-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#include <bitcoin-build-config.h> // IWYU pragma: keep7#include <qt/bitcoin.h>9#include <chainparams.h>10#include <common/args.h>11#include <common/init.h>12#include <common/system.h>13#include <init.h>14#include <interfaces/handler.h>15#include <interfaces/init.h>16#include <interfaces/node.h>17#include <node/context.h>18#include <node/interface_ui.h>19#include <noui.h>20#include <qt/bitcoingui.h>21#include <qt/clientmodel.h>22#include <qt/guiconstants.h>23#include <qt/guiutil.h>24#include <qt/initexecutor.h>25#include <qt/intro.h>26#include <qt/networkstyle.h>27#include <qt/optionsmodel.h>28#include <qt/platformstyle.h>29#include <qt/splashscreen.h>30#include <qt/utilitydialog.h>31#include <qt/winshutdownmonitor.h>32#include <uint256.h>33#include <util/btcsignals.h>34#include <util/exception.h>35#include <util/log.h>36#include <util/string.h>37#include <util/threadnames.h>38#include <util/translation.h>39#include <validation.h>41#ifdef ENABLE_WALLET42#include <qt/paymentserver.h>43#include <qt/walletcontroller.h>44#include <qt/walletmodel.h>45#include <wallet/types.h>46#endif // ENABLE_WALLET48#include <chrono>49#include <memory>51#include <QApplication>52#include <QDebug>53#include <QLatin1String>54#include <QLibraryInfo>55#include <QLocale>56#include <QMessageBox>57#include <QSettings>58#include <QThread>59#include <QTimer>60#include <QTranslator>61#include <QWindow>63// Declare meta types used for QMetaObject::invokeMethod64Q_DECLARE_METATYPE(bool*)65Q_DECLARE_METATYPE(CAmount)66Q_DECLARE_METATYPE(SynchronizationState)67Q_DECLARE_METATYPE(SyncType)68Q_DECLARE_METATYPE(uint256)69#ifdef ENABLE_WALLET70Q_DECLARE_METATYPE(wallet::AddressPurpose)71#endif // ENABLE_WALLET73using util::MakeUnorderedList;75static void RegisterMetaTypes()76{77// Register meta types used for QMetaObject::invokeMethod and Qt::QueuedConnection78qRegisterMetaType<bool*>();79qRegisterMetaType<SynchronizationState>();80qRegisterMetaType<SyncType>();81#ifdef ENABLE_WALLET82qRegisterMetaType<WalletModel*>();83qRegisterMetaType<wallet::AddressPurpose>();84#endif // ENABLE_WALLET85// Register typedefs (see https://doc.qt.io/qt-5/qmetatype.html#qRegisterMetaType)86// IMPORTANT: if CAmount is no longer a typedef use the normal variant above (see https://doc.qt.io/qt-5/qmetatype.html#qRegisterMetaType-1)87qRegisterMetaType<CAmount>("CAmount");88qRegisterMetaType<size_t>("size_t");90qRegisterMetaType<std::function<void()>>("std::function<void()>");91qRegisterMetaType<QMessageBox::Icon>("QMessageBox::Icon");92qRegisterMetaType<interfaces::BlockAndHeaderTipInfo>("interfaces::BlockAndHeaderTipInfo");93qRegisterMetaType<BitcoinUnit>("BitcoinUnit");94}96static QString GetLangTerritory()97{98QSettings settings;99// Get desired locale (e.g. "de_DE")100// 1) System default language101QString lang_territory = QLocale::system().name();102// 2) Language from QSettings103QString lang_territory_qsettings = settings.value("language", "").toString();104if(!lang_territory_qsettings.isEmpty())105lang_territory = lang_territory_qsettings;106// 3) -lang command line argument107lang_territory = QString::fromStdString(gArgs.GetArg("-lang", lang_territory.toStdString()));108return lang_territory;109}111/** Set up translations */112static void initTranslations(QTranslator &qtTranslatorBase, QTranslator &qtTranslator, QTranslator &translatorBase, QTranslator &translator)113{114// Remove old translators115QApplication::removeTranslator(&qtTranslatorBase);116QApplication::removeTranslator(&qtTranslator);117QApplication::removeTranslator(&translatorBase);118QApplication::removeTranslator(&translator);120// Get desired locale (e.g. "de_DE")121// 1) System default language122QString lang_territory = GetLangTerritory();124// Convert to "de" only by truncating "_DE"125QString lang = lang_territory;126lang.truncate(lang_territory.lastIndexOf('_'));128// Load language files for configured locale:129// - First load the translator for the base language, without territory130// - Then load the more specific locale translator132const QString translation_path{QLibraryInfo::path(QLibraryInfo::TranslationsPath)};133// Load e.g. qt_de.qm134if (qtTranslatorBase.load("qt_" + lang, translation_path)) {135QApplication::installTranslator(&qtTranslatorBase);136}138// Load e.g. qt_de_DE.qm139if (qtTranslator.load("qt_" + lang_territory, translation_path)) {140QApplication::installTranslator(&qtTranslator);141}143// Load e.g. bitcoin_de.qm (shortcut "de" needs to be defined in bitcoin.qrc)144if (translatorBase.load(lang, ":/translations/")) {145QApplication::installTranslator(&translatorBase);146}148// Load e.g. bitcoin_de_DE.qm (shortcut "de_DE" needs to be defined in bitcoin.qrc)149if (translator.load(lang_territory, ":/translations/")) {150QApplication::installTranslator(&translator);151}152}154static bool ErrorSettingsRead(const bilingual_str& error, const std::vector<std::string>& details)155{156QMessageBox messagebox(QMessageBox::Critical, CLIENT_NAME, QString::fromStdString(strprintf("%s.", error.translated)), QMessageBox::Reset | QMessageBox::Abort);157/*: Explanatory text shown on startup when the settings file cannot be read.158Prompts user to make a choice between resetting or aborting. */159messagebox.setInformativeText(QObject::tr("Do you want to reset settings to default values, or to abort without making changes?"));160messagebox.setDetailedText(QString::fromStdString(MakeUnorderedList(details)));161messagebox.setTextFormat(Qt::PlainText);162messagebox.setDefaultButton(QMessageBox::Reset);163switch (messagebox.exec()) {164case QMessageBox::Reset:165return false;166case QMessageBox::Abort:167return true;168default:169assert(false);170}171}173static void ErrorSettingsWrite(const bilingual_str& error, const std::vector<std::string>& details)174{175QMessageBox messagebox(QMessageBox::Critical, CLIENT_NAME, QString::fromStdString(strprintf("%s.", error.translated)), QMessageBox::Ok);176/*: Explanatory text shown on startup when the settings file could not be written.177Prompts user to check that we have the ability to write to the file.178Explains that the user has the option of running without a settings file.*/179messagebox.setInformativeText(QObject::tr("A fatal error occurred. Check that settings file is writable, or try running with -nosettings."));180messagebox.setDetailedText(QString::fromStdString(MakeUnorderedList(details)));181messagebox.setTextFormat(Qt::PlainText);182messagebox.setDefaultButton(QMessageBox::Ok);183messagebox.exec();184}186/* qDebug() message handler --> debug.log */187void DebugMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString &msg)188{189Q_UNUSED(context);190if (type == QtDebugMsg) {191LogDebug(BCLog::QT, "GUI: %s\n", msg.toStdString());192} else {193LogInfo("GUI: %s", msg.toStdString());194}195}197static int qt_argc = 1;198static const char* qt_argv = "bitcoin-qt";200BitcoinApplication::BitcoinApplication()201: QApplication(qt_argc, const_cast<char**>(&qt_argv))202{203// Qt runs setlocale(LC_ALL, "") on initialization.204RegisterMetaTypes();205setQuitOnLastWindowClosed(false);206}208void BitcoinApplication::setupPlatformStyle()209{210// UI per-platform customization211// This must be done inside the BitcoinApplication constructor, or after it, because212// PlatformStyle::instantiate requires a QApplication213std::string platformName;214platformName = gArgs.GetArg("-uiplatform", BitcoinGUI::DEFAULT_UIPLATFORM);215platformStyle = PlatformStyle::instantiate(QString::fromStdString(platformName));216if (!platformStyle) // Fall back to "other" if specified name not found217platformStyle = PlatformStyle::instantiate("other");218assert(platformStyle);219}221BitcoinApplication::~BitcoinApplication()222{223m_executor.reset();225delete window;226window = nullptr;227delete platformStyle;228platformStyle = nullptr;229}231#ifdef ENABLE_WALLET232void BitcoinApplication::createPaymentServer()233{234paymentServer = new PaymentServer(this);235}236#endif238bool BitcoinApplication::createOptionsModel(bool resetSettings)239{240optionsModel = new OptionsModel(node(), this);241if (resetSettings) {242optionsModel->Reset();243}244bilingual_str error;245if (!optionsModel->Init(error)) {246fs::path settings_path;247if (gArgs.GetSettingsPath(&settings_path)) {248error += Untranslated("\n");249std::string quoted_path = strprintf("%s", fs::quoted(fs::PathToString(settings_path)));250error.original += strprintf("Settings file %s might be corrupt or invalid.", quoted_path);
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.