aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/qt/bitcoin.cpp21
-rw-r--r--src/qt/guiutil.cpp12
-rw-r--r--src/qt/guiutil.h8
3 files changed, 23 insertions, 18 deletions
diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp
index 738464668f..0f7c96e6a8 100644
--- a/src/qt/bitcoin.cpp
+++ b/src/qt/bitcoin.cpp
@@ -5,6 +5,7 @@
#include "clientmodel.h"
#include "walletmodel.h"
#include "optionsmodel.h"
+#include "guiutil.h"
#include "headers.h"
#include "init.h"
@@ -12,7 +13,6 @@
#include <QApplication>
#include <QMessageBox>
-#include <QThread>
#include <QTextCodec>
#include <QLocale>
#include <QTranslator>
@@ -70,15 +70,7 @@ bool ThreadSafeAskFee(int64 nFeeRequired, const std::string& strCaption, wxWindo
return true;
bool payFee = false;
- // Call slot on GUI thread.
- // If called from another thread, use a blocking QueuedConnection.
- Qt::ConnectionType connectionType = Qt::DirectConnection;
- if(QThread::currentThread() != QCoreApplication::instance()->thread())
- {
- connectionType = Qt::BlockingQueuedConnection;
- }
-
- QMetaObject::invokeMethod(guiref, "askFee", connectionType,
+ QMetaObject::invokeMethod(guiref, "askFee", GUIUtil::blockingGUIThreadConnection(),
Q_ARG(qint64, nFeeRequired),
Q_ARG(bool*, &payFee));
@@ -90,14 +82,7 @@ void ThreadSafeHandleURL(const std::string& strURL)
if(!guiref)
return;
- // Call slot on GUI thread.
- // If called from another thread, use a blocking QueuedConnection.
- Qt::ConnectionType connectionType = Qt::DirectConnection;
- if(QThread::currentThread() != QCoreApplication::instance()->thread())
- {
- connectionType = Qt::BlockingQueuedConnection;
- }
- QMetaObject::invokeMethod(guiref, "handleURL", connectionType,
+ QMetaObject::invokeMethod(guiref, "handleURL", GUIUtil::blockingGUIThreadConnection(),
Q_ARG(QString, QString::fromStdString(strURL)));
}
diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp
index ac69bd07e9..ad530a78e4 100644
--- a/src/qt/guiutil.cpp
+++ b/src/qt/guiutil.cpp
@@ -17,6 +17,7 @@
#include <QClipboard>
#include <QFileDialog>
#include <QDesktopServices>
+#include <QThread>
QString GUIUtil::dateTimeStr(qint64 nTime)
{
@@ -184,3 +185,14 @@ QString GUIUtil::getSaveFileName(QWidget *parent, const QString &caption,
return result;
}
+Qt::ConnectionType GUIUtil::blockingGUIThreadConnection()
+{
+ if(QThread::currentThread() != QCoreApplication::instance()->thread())
+ {
+ return Qt::BlockingQueuedConnection;
+ }
+ else
+ {
+ return Qt::DirectConnection;
+ }
+}
diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h
index 75ba53f206..06426d76bc 100644
--- a/src/qt/guiutil.h
+++ b/src/qt/guiutil.h
@@ -60,6 +60,14 @@ public:
const QString &dir=QString(), const QString &filter=QString(),
QString *selectedSuffixOut=0);
+
+ /** Get connection type to call object slot in GUI thread with invokeMethod. The call will be blocking.
+
+ @returns If called from the GUI thread, return a Qt::DirectConnection.
+ If called from another thread, return a Qt::BlockingQueuedConnection.
+ */
+ static Qt::ConnectionType blockingGUIThreadConnection();
+
};
#endif // GUIUTIL_H