aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@protonmail.com>2019-10-26 13:00:01 +0200
committerWladimir J. van der Laan <laanwj@protonmail.com>2019-10-26 13:00:16 +0200
commit9bd109b78d938dfe95d31d089e0c74061c30103f (patch)
treefa20da1a3ce254e1b0aba36af28d4d5da024a230 /src
parent3f875744cb61d63f010900dafdb7bbc451de5ead (diff)
parenta8f5026d6d992fd8d72908c848c5028f0f9a8cd1 (diff)
Merge #17120: gui: Fix start timer from non QThread
a8f5026d6d992fd8d72908c848c5028f0f9a8cd1 gui: Fix start timer from non QThread (João Barbosa) Pull request description: Fixes #16296. ACKs for top commit: laanwj: code review ACK a8f5026d6d992fd8d72908c848c5028f0f9a8cd1 Tree-SHA512: d7b05ac88e188de16cbbe80cb2f773b7976ee07ee876ac94a93f9351856c4f3a9d66a531d3f3748d2dccff8c8d77d9d8227433069ed5909c32be2efeaa32f655
Diffstat (limited to 'src')
-rw-r--r--src/qt/walletcontroller.cpp6
-rw-r--r--src/qt/walletmodel.cpp13
-rw-r--r--src/qt/walletmodel.h5
3 files changed, 17 insertions, 7 deletions
diff --git a/src/qt/walletcontroller.cpp b/src/qt/walletcontroller.cpp
index a7edf442e5..4c253f8ddd 100644
--- a/src/qt/walletcontroller.cpp
+++ b/src/qt/walletcontroller.cpp
@@ -109,6 +109,12 @@ WalletModel* WalletController::getOrCreateWallet(std::unique_ptr<interfaces::Wal
wallet_model->setParent(this);
m_wallets.push_back(wallet_model);
+ // WalletModel::startPollBalance needs to be called in a thread managed by
+ // Qt because of startTimer. Considering the current thread can be a RPC
+ // thread, better delegate the calling to Qt with Qt::AutoConnection.
+ const bool called = QMetaObject::invokeMethod(wallet_model, "startPollBalance");
+ assert(called);
+
connect(wallet_model, &WalletModel::unload, [this, wallet_model] {
// Defer removeAndDeleteWallet when no modal widget is active.
// TODO: remove this workaround by removing usage of QDiallog::exec.
diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp
index 08ea1c2409..33801d3907 100644
--- a/src/qt/walletmodel.cpp
+++ b/src/qt/walletmodel.cpp
@@ -44,11 +44,6 @@ WalletModel::WalletModel(std::unique_ptr<interfaces::Wallet> wallet, interfaces:
transactionTableModel = new TransactionTableModel(platformStyle, this);
recentRequestsTableModel = new RecentRequestsTableModel(this);
- // This timer will be fired repeatedly to update the balance
- pollTimer = new QTimer(this);
- connect(pollTimer, &QTimer::timeout, this, &WalletModel::pollBalanceChanged);
- pollTimer->start(MODEL_UPDATE_DELAY);
-
subscribeToCoreSignals();
}
@@ -57,6 +52,14 @@ WalletModel::~WalletModel()
unsubscribeFromCoreSignals();
}
+void WalletModel::startPollBalance()
+{
+ // This timer will be fired repeatedly to update the balance
+ QTimer* timer = new QTimer(this);
+ connect(timer, &QTimer::timeout, this, &WalletModel::pollBalanceChanged);
+ timer->start(MODEL_UPDATE_DELAY);
+}
+
void WalletModel::updateStatus()
{
EncryptionStatus newEncryptionStatus = getEncryptionStatus();
diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h
index 5181d1c83b..d21dec118a 100644
--- a/src/qt/walletmodel.h
+++ b/src/qt/walletmodel.h
@@ -235,8 +235,6 @@ private:
EncryptionStatus cachedEncryptionStatus;
int cachedNumBlocks;
- QTimer *pollTimer;
-
void subscribeToCoreSignals();
void unsubscribeFromCoreSignals();
void checkBalanceChanged(const interfaces::WalletBalances& new_balances);
@@ -272,6 +270,9 @@ Q_SIGNALS:
void canGetAddressesChanged();
public Q_SLOTS:
+ /* Starts a timer to periodically update the balance */
+ void startPollBalance();
+
/* Wallet status might have changed */
void updateStatus();
/* New transaction, or transaction changed status */