2828#include < qml/models/peerdetailsmodel.h>
2929#include < qml/models/peerlistsortproxy.h>
3030#include < qml/models/walletlistmodel.h>
31+ #include < qml/models/walletqmlmodel.h>
3132#include < qml/imageprovider.h>
3233#include < qml/util.h>
33- #include < qml/walletcontroller .h>
34+ #include < qml/walletqmlcontroller .h>
3435#include < qt/guiutil.h>
3536#include < qt/initexecutor.h>
3637#include < qt/networkstyle.h>
@@ -259,8 +260,17 @@ int QmlGuiMain(int argc, char* argv[])
259260
260261 NodeModel node_model{*node};
261262 InitExecutor init_executor{*node};
263+ #ifdef ENABLE_WALLET
264+ WalletQmlController wallet_controller (*node);
265+ QObject::connect (&init_executor, &InitExecutor::initializeResult, &wallet_controller, &WalletQmlController::initialize);
266+ #endif
262267 QObject::connect (&node_model, &NodeModel::requestedInitialize, &init_executor, &InitExecutor::initialize);
263- QObject::connect (&node_model, &NodeModel::requestedShutdown, &init_executor, &InitExecutor::shutdown);
268+ QObject::connect (&node_model, &NodeModel::requestedShutdown, [&] {
269+ #ifdef ENABLE_WALLET
270+ wallet_controller.unloadWallets ();
271+ #endif
272+ init_executor.shutdown ();
273+ });
264274 QObject::connect (&init_executor, &InitExecutor::initializeResult, &node_model, &NodeModel::initializeResult);
265275 QObject::connect (&init_executor, &InitExecutor::shutdownResult, qGuiApp, &QGuiApplication::quit, Qt::QueuedConnection);
266276 // QObject::connect(&init_executor, &InitExecutor::runawayException, &node_model, &NodeModel::handleRunawayException);
@@ -277,8 +287,12 @@ int QmlGuiMain(int argc, char* argv[])
277287 QObject::connect (&node_model, &NodeModel::setTimeRatioList, &chain_model, &ChainModel::setTimeRatioList);
278288 QObject::connect (&node_model, &NodeModel::setTimeRatioListInitial, &chain_model, &ChainModel::setTimeRatioListInitial);
279289
290+
280291 qGuiApp->setQuitOnLastWindowClosed (false );
281292 QObject::connect (qGuiApp, &QGuiApplication::lastWindowClosed, [&] {
293+ #ifdef ENABLE_WALLET
294+ wallet_controller.unloadWallets ();
295+ #endif
282296 node->startShutdown ();
283297 });
284298
@@ -289,23 +303,22 @@ int QmlGuiMain(int argc, char* argv[])
289303 GUIUtil::LoadFont (" :/fonts/inter/regular" );
290304 GUIUtil::LoadFont (" :/fonts/inter/semibold" );
291305
292- WalletController wallet_controller (*node);
293-
294306 QQmlApplicationEngine engine;
295307
296308 QScopedPointer<const NetworkStyle> network_style{NetworkStyle::instantiate (Params ().GetChainType ())};
297309 assert (!network_style.isNull ());
298310 engine.addImageProvider (QStringLiteral (" images" ), new ImageProvider{network_style.data ()});
299311
300- WalletListModel wallet_list_model{*node, nullptr };
301-
302312 engine.rootContext ()->setContextProperty (" networkTrafficTower" , &network_traffic_tower);
303313 engine.rootContext ()->setContextProperty (" nodeModel" , &node_model);
304314 engine.rootContext ()->setContextProperty (" chainModel" , &chain_model);
305315 engine.rootContext ()->setContextProperty (" peerTableModel" , &peer_model);
306316 engine.rootContext ()->setContextProperty (" peerListModelProxy" , &peer_model_sort_proxy);
317+ #ifdef ENABLE_WALLET
318+ WalletListModel wallet_list_model{*node, nullptr };
307319 engine.rootContext ()->setContextProperty (" walletController" , &wallet_controller);
308320 engine.rootContext ()->setContextProperty (" walletListModel" , &wallet_list_model);
321+ #endif
309322
310323 OptionsQmlModel options_model (*node, !need_onboarding.toBool ());
311324 engine.rootContext ()->setContextProperty (" optionsModel" , &options_model);
@@ -318,6 +331,10 @@ int QmlGuiMain(int argc, char* argv[])
318331 qmlRegisterType<LineGraph>(" org.bitcoincore.qt" , 1 , 0 , " LineGraph" );
319332 qmlRegisterUncreatableType<PeerDetailsModel>(" org.bitcoincore.qt" , 1 , 0 , " PeerDetailsModel" , " " );
320333
334+ #ifdef ENABLE_WALLET
335+ qmlRegisterUncreatableType<WalletQmlModel>(" org.bitcoincore.qt" , 1 , 0 , " WalletQmlModel" ,
336+ " WalletQmlModel cannot be instantiated from QML" );
337+ #endif
321338
322339 engine.load (QUrl (QStringLiteral (" qrc:///qml/pages/main.qml" )));
323340 if (engine.rootObjects ().isEmpty ()) {
0 commit comments