@@ -267,58 +267,62 @@ void BitcoinGUI::createToolBars()
267267void BitcoinGUI::setClientModel (ClientModel *clientModel)
268268{
269269 this ->clientModel = clientModel;
270-
271- if (clientModel->isTestNet ())
270+ if (clientModel)
272271 {
273- QString title_testnet = windowTitle () + QString (" " ) + tr (" [testnet]" );
274- setWindowTitle (title_testnet);
272+ if (clientModel->isTestNet ())
273+ {
274+ QString title_testnet = windowTitle () + QString (" " ) + tr (" [testnet]" );
275+ setWindowTitle (title_testnet);
275276#ifndef Q_WS_MAC
276- setWindowIcon (QIcon (" :icons/bitcoin_testnet" ));
277+ setWindowIcon (QIcon (" :icons/bitcoin_testnet" ));
277278#else
278- MacDockIconHandler::instance ()->setIcon (QIcon (" :icons/bitcoin_testnet" ));
279+ MacDockIconHandler::instance ()->setIcon (QIcon (" :icons/bitcoin_testnet" ));
279280#endif
280- if (trayIcon)
281- {
282- trayIcon->setToolTip (title_testnet);
283- trayIcon->setIcon (QIcon (" :/icons/toolbar_testnet" ));
281+ if (trayIcon)
282+ {
283+ trayIcon->setToolTip (title_testnet);
284+ trayIcon->setIcon (QIcon (" :/icons/toolbar_testnet" ));
285+ }
284286 }
285- }
286287
287- // Keep up to date with client
288- setNumConnections (clientModel->getNumConnections ());
289- connect (clientModel, SIGNAL (numConnectionsChanged (int )), this , SLOT (setNumConnections (int )));
288+ // Keep up to date with client
289+ setNumConnections (clientModel->getNumConnections ());
290+ connect (clientModel, SIGNAL (numConnectionsChanged (int )), this , SLOT (setNumConnections (int )));
290291
291- setNumBlocks (clientModel->getNumBlocks ());
292- connect (clientModel, SIGNAL (numBlocksChanged (int )), this , SLOT (setNumBlocks (int )));
292+ setNumBlocks (clientModel->getNumBlocks ());
293+ connect (clientModel, SIGNAL (numBlocksChanged (int )), this , SLOT (setNumBlocks (int )));
293294
294- // Report errors from network/worker thread
295- connect (clientModel, SIGNAL (error (QString,QString)), this , SLOT (error (QString,QString)));
295+ // Report errors from network/worker thread
296+ connect (clientModel, SIGNAL (error (QString,QString)), this , SLOT (error (QString,QString)));
297+ }
296298}
297299
298300void BitcoinGUI::setWalletModel (WalletModel *walletModel)
299301{
300302 this ->walletModel = walletModel;
303+ if (walletModel)
304+ {
305+ // Report errors from wallet thread
306+ connect (walletModel, SIGNAL (error (QString,QString)), this , SLOT (error (QString,QString)));
301307
302- // Report errors from wallet thread
303- connect (walletModel, SIGNAL (error (QString,QString)), this , SLOT (error (QString,QString)));
304-
305- // Put transaction list in tabs
306- transactionView->setModel (walletModel);
308+ // Put transaction list in tabs
309+ transactionView->setModel (walletModel);
307310
308- overviewPage->setModel (walletModel);
309- addressBookPage->setModel (walletModel->getAddressTableModel ());
310- receiveCoinsPage->setModel (walletModel->getAddressTableModel ());
311- sendCoinsPage->setModel (walletModel);
311+ overviewPage->setModel (walletModel);
312+ addressBookPage->setModel (walletModel->getAddressTableModel ());
313+ receiveCoinsPage->setModel (walletModel->getAddressTableModel ());
314+ sendCoinsPage->setModel (walletModel);
312315
313- setEncryptionStatus (walletModel->getEncryptionStatus ());
314- connect (walletModel, SIGNAL (encryptionStatusChanged (int )), this , SLOT (setEncryptionStatus (int )));
316+ setEncryptionStatus (walletModel->getEncryptionStatus ());
317+ connect (walletModel, SIGNAL (encryptionStatusChanged (int )), this , SLOT (setEncryptionStatus (int )));
315318
316- // Balloon popup for new transaction
317- connect (walletModel->getTransactionTableModel (), SIGNAL (rowsInserted (QModelIndex,int ,int )),
318- this , SLOT (incomingTransaction (QModelIndex,int ,int )));
319+ // Balloon popup for new transaction
320+ connect (walletModel->getTransactionTableModel (), SIGNAL (rowsInserted (QModelIndex,int ,int )),
321+ this , SLOT (incomingTransaction (QModelIndex,int ,int )));
319322
320- // Ask for passphrase if needed
321- connect (walletModel, SIGNAL (requireUnlock ()), this , SLOT (unlockWallet ()));
323+ // Ask for passphrase if needed
324+ connect (walletModel, SIGNAL (requireUnlock ()), this , SLOT (unlockWallet ()));
325+ }
322326}
323327
324328void BitcoinGUI::createTrayIcon ()
@@ -369,6 +373,8 @@ void BitcoinGUI::trayIconActivated(QSystemTrayIcon::ActivationReason reason)
369373
370374void BitcoinGUI::optionsClicked ()
371375{
376+ if (!clientModel || !clientModel->getOptionsModel ())
377+ return ;
372378 OptionsDialog dlg;
373379 dlg.setModel (clientModel->getOptionsModel ());
374380 dlg.exec ();
@@ -398,6 +404,8 @@ void BitcoinGUI::setNumConnections(int count)
398404
399405void BitcoinGUI::setNumBlocks (int count)
400406{
407+ if (!clientModel)
408+ return ;
401409 int initTotal = clientModel->getNumBlocksAtStartup ();
402410 int total = clientModel->getNumBlocksOfPeers ();
403411 QString tooltip;
@@ -492,13 +500,16 @@ void BitcoinGUI::changeEvent(QEvent *e)
492500
493501void BitcoinGUI::closeEvent (QCloseEvent *event)
494502{
495- #ifndef Q_WS_MAC // Ignored on Mac
496- if (!clientModel->getOptionsModel ()->getMinimizeToTray () &&
497- !clientModel->getOptionsModel ()->getMinimizeOnClose ())
503+ if (clientModel)
498504 {
499- qApp->quit ();
500- }
505+ #ifndef Q_WS_MAC // Ignored on Mac
506+ if (!clientModel->getOptionsModel ()->getMinimizeToTray () &&
507+ !clientModel->getOptionsModel ()->getMinimizeOnClose ())
508+ {
509+ qApp->quit ();
510+ }
501511#endif
512+ }
502513 QMainWindow::closeEvent (event);
503514}
504515
@@ -517,6 +528,8 @@ void BitcoinGUI::askFee(qint64 nFeeRequired, bool *payFee)
517528
518529void BitcoinGUI::incomingTransaction (const QModelIndex & parent, int start, int end)
519530{
531+ if (!walletModel || !clientModel)
532+ return ;
520533 TransactionTableModel *ttm = walletModel->getTransactionTableModel ();
521534 qint64 amount = ttm->index (start, TransactionTableModel::Amount, parent)
522535 .data (Qt::EditRole).toULongLong ();
@@ -654,6 +667,8 @@ void BitcoinGUI::setEncryptionStatus(int status)
654667
655668void BitcoinGUI::encryptWallet (bool status)
656669{
670+ if (!walletModel)
671+ return ;
657672 AskPassphraseDialog dlg (status ? AskPassphraseDialog::Encrypt:
658673 AskPassphraseDialog::Decrypt, this );
659674 dlg.setModel (walletModel);
@@ -671,6 +686,8 @@ void BitcoinGUI::changePassphrase()
671686
672687void BitcoinGUI::unlockWallet ()
673688{
689+ if (!walletModel)
690+ return ;
674691 // Unlock wallet when requested by wallet model
675692 if (walletModel->getEncryptionStatus () == WalletModel::Locked)
676693 {
0 commit comments