mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-28 09:51:31 +02:00
gui: Fix start timer from non QThread
This commit is contained in:
parent
561a7d3047
commit
a8f5026d6d
@ -108,6 +108,12 @@ WalletModel* WalletController::getOrCreateWallet(std::unique_ptr<interfaces::Wal
|
|||||||
wallet_model->setParent(this);
|
wallet_model->setParent(this);
|
||||||
m_wallets.push_back(wallet_model);
|
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] {
|
connect(wallet_model, &WalletModel::unload, [this, wallet_model] {
|
||||||
// Defer removeAndDeleteWallet when no modal widget is active.
|
// Defer removeAndDeleteWallet when no modal widget is active.
|
||||||
// TODO: remove this workaround by removing usage of QDiallog::exec.
|
// TODO: remove this workaround by removing usage of QDiallog::exec.
|
||||||
|
@ -44,11 +44,6 @@ WalletModel::WalletModel(std::unique_ptr<interfaces::Wallet> wallet, interfaces:
|
|||||||
transactionTableModel = new TransactionTableModel(platformStyle, this);
|
transactionTableModel = new TransactionTableModel(platformStyle, this);
|
||||||
recentRequestsTableModel = new RecentRequestsTableModel(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();
|
subscribeToCoreSignals();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,6 +52,14 @@ WalletModel::~WalletModel()
|
|||||||
unsubscribeFromCoreSignals();
|
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()
|
void WalletModel::updateStatus()
|
||||||
{
|
{
|
||||||
EncryptionStatus newEncryptionStatus = getEncryptionStatus();
|
EncryptionStatus newEncryptionStatus = getEncryptionStatus();
|
||||||
|
@ -255,8 +255,6 @@ private:
|
|||||||
EncryptionStatus cachedEncryptionStatus;
|
EncryptionStatus cachedEncryptionStatus;
|
||||||
int cachedNumBlocks;
|
int cachedNumBlocks;
|
||||||
|
|
||||||
QTimer *pollTimer;
|
|
||||||
|
|
||||||
void subscribeToCoreSignals();
|
void subscribeToCoreSignals();
|
||||||
void unsubscribeFromCoreSignals();
|
void unsubscribeFromCoreSignals();
|
||||||
void checkBalanceChanged(const interfaces::WalletBalances& new_balances);
|
void checkBalanceChanged(const interfaces::WalletBalances& new_balances);
|
||||||
@ -292,6 +290,9 @@ Q_SIGNALS:
|
|||||||
void canGetAddressesChanged();
|
void canGetAddressesChanged();
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
|
/* Starts a timer to periodically update the balance */
|
||||||
|
void startPollBalance();
|
||||||
|
|
||||||
/* Wallet status might have changed */
|
/* Wallet status might have changed */
|
||||||
void updateStatus();
|
void updateStatus();
|
||||||
/* New transaction, or transaction changed status */
|
/* New transaction, or transaction changed status */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user