Skip to content

Commit 0b8e286

Browse files
committed
Merge #589: Getting ready to Qt 6 (7/n). Do not pass WalletModel* to a queued connection
ab73d59 Do not pass `WalletModel*` to queued connection (Hennadii Stepanov) fdf7285 refactor: Make `RPCExecutor*` a member of the `RPCConsole` class (Hennadii Stepanov) 61457c1 refactor: Guard `RPCConsole::{add,remove}Wallet()` with `ENABLE_WALLET` (Hennadii Stepanov) Pull request description: On master (094d9fd), the following queued connection https://github.com/bitcoin-core/gui/blob/094d9fda5ccee7d78a2e3d8b1eec17b8b6a33466/src/qt/rpcconsole.cpp#L1107 uses a `const WalletModel*` parameter regardless whether the `ENABLE_WALLET` macro is defined. Although this code works in Qt 5, it is flawed. On Qt 6, the code gets broken because the fully defined `WalletModel` type is required which is not the case if `ENABLE_WALLET` is undefined. This PR fixes the issue described above. ACKs for top commit: promag: ACK ab73d59 jarolrod: code review ACK ab73d59 Tree-SHA512: 544ba984da4480aa34f1516a737d6034eb5616b8f78db38dc9bf2d15c15251957bc0b0c9b0d5a365552da9b64a850801a6f4caa12b0ac220f51bd2b334fbe545
2 parents f58c1f1 + ab73d59 commit 0b8e286

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

src/qt/rpcconsole.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,8 +1032,9 @@ void RPCConsole::on_lineEdit_returnPressed()
10321032

10331033
ui->lineEdit->clear();
10341034

1035+
WalletModel* wallet_model{nullptr};
10351036
#ifdef ENABLE_WALLET
1036-
WalletModel* wallet_model = ui->WalletSelector->currentData().value<WalletModel*>();
1037+
wallet_model = ui->WalletSelector->currentData().value<WalletModel*>();
10371038

10381039
if (m_last_wallet_model != wallet_model) {
10391040
if (wallet_model) {
@@ -1049,7 +1050,10 @@ void RPCConsole::on_lineEdit_returnPressed()
10491050
//: A console message indicating an entered command is currently being executed.
10501051
message(CMD_REPLY, tr("Executing…"));
10511052
m_is_executing = true;
1052-
Q_EMIT cmdRequest(cmd, m_last_wallet_model);
1053+
1054+
QMetaObject::invokeMethod(m_executor, [this, cmd, wallet_model] {
1055+
m_executor->request(cmd, wallet_model);
1056+
});
10531057

10541058
cmd = QString::fromStdString(strFilteredCmd);
10551059

@@ -1091,28 +1095,25 @@ void RPCConsole::browseHistory(int offset)
10911095

10921096
void RPCConsole::startExecutor()
10931097
{
1094-
RPCExecutor *executor = new RPCExecutor(m_node);
1095-
executor->moveToThread(&thread);
1098+
m_executor = new RPCExecutor(m_node);
1099+
m_executor->moveToThread(&thread);
10961100

10971101
// Replies from executor object must go to this object
1098-
connect(executor, &RPCExecutor::reply, this, [this](int category, const QString& command) {
1102+
connect(m_executor, &RPCExecutor::reply, this, [this](int category, const QString& command) {
10991103
// Remove "Executing…" message.
11001104
ui->messagesWidget->undo();
11011105
message(category, command);
11021106
scrollToEnd();
11031107
m_is_executing = false;
11041108
});
11051109

1106-
// Requests from this object must go to executor
1107-
connect(this, &RPCConsole::cmdRequest, executor, &RPCExecutor::request);
1108-
11091110
// Make sure executor object is deleted in its own thread
1110-
connect(&thread, &QThread::finished, executor, &RPCExecutor::deleteLater);
1111+
connect(&thread, &QThread::finished, m_executor, &RPCExecutor::deleteLater);
11111112

11121113
// Default implementation of QThread::run() simply spins up an event loop in the thread,
11131114
// which is what we want.
11141115
thread.start();
1115-
QTimer::singleShot(0, executor, []() {
1116+
QTimer::singleShot(0, m_executor, []() {
11161117
util::ThreadRename("qt-rpcconsole");
11171118
});
11181119
}

src/qt/rpcconsole.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
#ifndef BITCOIN_QT_RPCCONSOLE_H
66
#define BITCOIN_QT_RPCCONSOLE_H
77

8+
#if defined(HAVE_CONFIG_H)
9+
#include <config/bitcoin-config.h>
10+
#endif
11+
812
#include <qt/guiutil.h>
913
#include <qt/peertablemodel.h>
1014

@@ -17,6 +21,7 @@
1721

1822
class ClientModel;
1923
class PlatformStyle;
24+
class RPCExecutor;
2025
class RPCTimerInterface;
2126
class WalletModel;
2227

@@ -49,8 +54,11 @@ class RPCConsole: public QWidget
4954
}
5055

5156
void setClientModel(ClientModel *model = nullptr, int bestblock_height = 0, int64_t bestblock_date = 0, double verification_progress = 0.0);
52-
void addWallet(WalletModel * const walletModel);
57+
58+
#ifdef ENABLE_WALLET
59+
void addWallet(WalletModel* const walletModel);
5360
void removeWallet(WalletModel* const walletModel);
61+
#endif // ENABLE_WALLET
5462

5563
enum MessageClass {
5664
MC_ERROR,
@@ -129,10 +137,6 @@ public Q_SLOTS:
129137
/** set which tab has the focus (is visible) */
130138
void setTabFocus(enum TabTypes tabType);
131139

132-
Q_SIGNALS:
133-
// For RPC command executor
134-
void cmdRequest(const QString &command, const WalletModel* wallet_model);
135-
136140
private:
137141
struct TranslatedStrings {
138142
const QString yes{tr("Yes")}, no{tr("No")}, to{tr("To")}, from{tr("From")},
@@ -166,6 +170,7 @@ public Q_SLOTS:
166170
int consoleFontSize = 0;
167171
QCompleter *autoCompleter = nullptr;
168172
QThread thread;
173+
RPCExecutor* m_executor{nullptr};
169174
WalletModel* m_last_wallet_model{nullptr};
170175
bool m_is_executing{false};
171176
QByteArray m_peer_widget_header_state;

0 commit comments

Comments
 (0)