mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-08-29 04:48:49 +02:00
Merge bitcoin-core/gui#587: refactor: Replace GUIUtil::ObjectInvoke()
with QMetaObject::invokeMethod()
6958a26aa1
Revert "qt: Add ObjectInvoke template function" (Hennadii Stepanov)249984f4f9
qt: Replace `GUIUtil::ObjectInvoke()` with `QMetaObject::invokeMethod()` (Hennadii Stepanov) Pull request description: A comment in5659e73493
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: tACK6958a26aa1
on Ubuntu 21.10, Qt 5.15.2. promag: Code review ACK6958a26aa1
. Tree-SHA512: 6a840289568113cf38df6c1092821d626c2d206768a21d4dc6846b9dcccb4130477adb45ba718bb6bc15a3041871a7df3238983ac03db80406732be597693266
This commit is contained in:
@@ -361,18 +361,6 @@ namespace GUIUtil
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Queue a function to run in an object's event loop. This can be
|
|
||||||
* replaced by a call to the QMetaObject::invokeMethod functor overload after Qt 5.10, but
|
|
||||||
* for now use a QObject::connect for compatibility with older Qt versions, based on
|
|
||||||
* https://stackoverflow.com/questions/21646467/how-to-execute-a-functor-or-a-lambda-in-a-given-thread-in-qt-gcd-style
|
|
||||||
*/
|
|
||||||
template <typename Fn>
|
|
||||||
void ObjectInvoke(QObject* object, Fn&& function, Qt::ConnectionType connection = Qt::QueuedConnection)
|
|
||||||
{
|
|
||||||
QObject source;
|
|
||||||
QObject::connect(&source, &QObject::destroyed, object, std::forward<Fn>(function), connection);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replaces a plain text link with an HTML tagged one.
|
* Replaces a plain text link with an HTML tagged one.
|
||||||
|
@@ -5,13 +5,13 @@
|
|||||||
#include <qt/initexecutor.h>
|
#include <qt/initexecutor.h>
|
||||||
|
|
||||||
#include <interfaces/node.h>
|
#include <interfaces/node.h>
|
||||||
#include <qt/guiutil.h>
|
|
||||||
#include <util/system.h>
|
#include <util/system.h>
|
||||||
#include <util/threadnames.h>
|
#include <util/threadnames.h>
|
||||||
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QMetaObject>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
@@ -39,7 +39,7 @@ void InitExecutor::handleRunawayException(const std::exception* e)
|
|||||||
|
|
||||||
void InitExecutor::initialize()
|
void InitExecutor::initialize()
|
||||||
{
|
{
|
||||||
GUIUtil::ObjectInvoke(&m_context, [this] {
|
QMetaObject::invokeMethod(&m_context, [this] {
|
||||||
try {
|
try {
|
||||||
util::ThreadRename("qt-init");
|
util::ThreadRename("qt-init");
|
||||||
qDebug() << "Running initialization in thread";
|
qDebug() << "Running initialization in thread";
|
||||||
@@ -56,7 +56,7 @@ void InitExecutor::initialize()
|
|||||||
|
|
||||||
void InitExecutor::shutdown()
|
void InitExecutor::shutdown()
|
||||||
{
|
{
|
||||||
GUIUtil::ObjectInvoke(&m_context, [this] {
|
QMetaObject::invokeMethod(&m_context, [this] {
|
||||||
try {
|
try {
|
||||||
qDebug() << "Running Shutdown in thread";
|
qDebug() << "Running Shutdown in thread";
|
||||||
m_node.appShutdown();
|
m_node.appShutdown();
|
||||||
|
@@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QMetaObject>
|
||||||
#include <QMutexLocker>
|
#include <QMutexLocker>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
@@ -135,7 +136,7 @@ WalletModel* WalletController::getOrCreateWallet(std::unique_ptr<interfaces::Wal
|
|||||||
// handled on the GUI event loop.
|
// handled on the GUI event loop.
|
||||||
wallet_model->moveToThread(thread());
|
wallet_model->moveToThread(thread());
|
||||||
// setParent(parent) must be called in the thread which created the parent object. More details in #18948.
|
// setParent(parent) must be called in the thread which created the parent object. More details in #18948.
|
||||||
GUIUtil::ObjectInvoke(this, [wallet_model, this] {
|
QMetaObject::invokeMethod(this, [wallet_model, this] {
|
||||||
wallet_model->setParent(this);
|
wallet_model->setParent(this);
|
||||||
}, GUIUtil::blockingGUIThreadConnection());
|
}, GUIUtil::blockingGUIThreadConnection());
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user