Skip to content

Commit be7a5f2

Browse files
committed
Merge #587: refactor: Replace GUIUtil::ObjectInvoke() with QMetaObject::invokeMethod()
6958a26 Revert "qt: Add ObjectInvoke template function" (Hennadii Stepanov) 249984f qt: Replace `GUIUtil::ObjectInvoke()` with `QMetaObject::invokeMethod()` (Hennadii Stepanov) Pull request description: A comment in 5659e73 states that `GUIUtil::ObjectInvoke` > can be replaced by a call to the QMetaObject::invokeMethod functor overload after Qt 5.10 ACKs for top commit: w0xlt: tACK 6958a26 on Ubuntu 21.10, Qt 5.15.2. promag: Code review ACK 6958a26. Tree-SHA512: 6a840289568113cf38df6c1092821d626c2d206768a21d4dc6846b9dcccb4130477adb45ba718bb6bc15a3041871a7df3238983ac03db80406732be597693266
2 parents 505ba39 + 6958a26 commit be7a5f2

File tree

3 files changed

+5
-16
lines changed

3 files changed

+5
-16
lines changed

src/qt/guiutil.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -361,18 +361,6 @@ namespace GUIUtil
361361
#endif
362362
}
363363

364-
/**
365-
* Queue a function to run in an object's event loop. This can be
366-
* replaced by a call to the QMetaObject::invokeMethod functor overload after Qt 5.10, but
367-
* for now use a QObject::connect for compatibility with older Qt versions, based on
368-
* https://stackoverflow.com/questions/21646467/how-to-execute-a-functor-or-a-lambda-in-a-given-thread-in-qt-gcd-style
369-
*/
370-
template <typename Fn>
371-
void ObjectInvoke(QObject* object, Fn&& function, Qt::ConnectionType connection = Qt::QueuedConnection)
372-
{
373-
QObject source;
374-
QObject::connect(&source, &QObject::destroyed, object, std::forward<Fn>(function), connection);
375-
}
376364

377365
/**
378366
* Replaces a plain text link with an HTML tagged one.

src/qt/initexecutor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
#include <qt/initexecutor.h>
66

77
#include <interfaces/node.h>
8-
#include <qt/guiutil.h>
98
#include <util/system.h>
109
#include <util/threadnames.h>
1110

1211
#include <exception>
1312

1413
#include <QDebug>
14+
#include <QMetaObject>
1515
#include <QObject>
1616
#include <QString>
1717
#include <QThread>
@@ -39,7 +39,7 @@ void InitExecutor::handleRunawayException(const std::exception* e)
3939

4040
void InitExecutor::initialize()
4141
{
42-
GUIUtil::ObjectInvoke(&m_context, [this] {
42+
QMetaObject::invokeMethod(&m_context, [this] {
4343
try {
4444
util::ThreadRename("qt-init");
4545
qDebug() << "Running initialization in thread";
@@ -56,7 +56,7 @@ void InitExecutor::initialize()
5656

5757
void InitExecutor::shutdown()
5858
{
59-
GUIUtil::ObjectInvoke(&m_context, [this] {
59+
QMetaObject::invokeMethod(&m_context, [this] {
6060
try {
6161
qDebug() << "Running Shutdown in thread";
6262
m_node.appShutdown();

src/qt/walletcontroller.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include <QApplication>
2626
#include <QMessageBox>
27+
#include <QMetaObject>
2728
#include <QMutexLocker>
2829
#include <QThread>
2930
#include <QTimer>
@@ -135,7 +136,7 @@ WalletModel* WalletController::getOrCreateWallet(std::unique_ptr<interfaces::Wal
135136
// handled on the GUI event loop.
136137
wallet_model->moveToThread(thread());
137138
// setParent(parent) must be called in the thread which created the parent object. More details in #18948.
138-
GUIUtil::ObjectInvoke(this, [wallet_model, this] {
139+
QMetaObject::invokeMethod(this, [wallet_model, this] {
139140
wallet_model->setParent(this);
140141
}, GUIUtil::blockingGUIThreadConnection());
141142

0 commit comments

Comments
 (0)