aboutsummaryrefslogtreecommitdiff
path: root/src/qt
diff options
context:
space:
mode:
Diffstat (limited to 'src/qt')
-rw-r--r--src/qt/callback.h30
-rw-r--r--src/qt/test/wallettests.cpp9
2 files changed, 34 insertions, 5 deletions
diff --git a/src/qt/callback.h b/src/qt/callback.h
new file mode 100644
index 0000000000..a8b593a652
--- /dev/null
+++ b/src/qt/callback.h
@@ -0,0 +1,30 @@
+#ifndef BITCOIN_QT_CALLBACK_H
+#define BITCOIN_QT_CALLBACK_H
+
+#include <QObject>
+
+class Callback : public QObject
+{
+ Q_OBJECT
+public Q_SLOTS:
+ virtual void call() = 0;
+};
+
+template <typename F>
+class FunctionCallback : public Callback
+{
+ F f;
+
+public:
+ FunctionCallback(F f_) : f(std::move(f_)) {}
+ ~FunctionCallback() override {}
+ void call() override { f(this); }
+};
+
+template <typename F>
+FunctionCallback<F>* makeCallback(F f)
+{
+ return new FunctionCallback<F>(std::move(f));
+}
+
+#endif // BITCOIN_QT_CALLBACK_H
diff --git a/src/qt/test/wallettests.cpp b/src/qt/test/wallettests.cpp
index 36d93361dd..b7c1e4c4d5 100644
--- a/src/qt/test/wallettests.cpp
+++ b/src/qt/test/wallettests.cpp
@@ -1,6 +1,7 @@
#include "wallettests.h"
#include "qt/bitcoinamountfield.h"
+#include "qt/callback.h"
#include "qt/optionsmodel.h"
#include "qt/platformstyle.h"
#include "qt/qvalidatedlineedit.h"
@@ -22,9 +23,7 @@ namespace
//! Press "Yes" button in modal send confirmation dialog.
void ConfirmSend()
{
- QTimer* timer = new QTimer;
- timer->setSingleShot(true);
- QObject::connect(timer, &QTimer::timeout, []() {
+ QTimer::singleShot(0, makeCallback([](Callback* callback) {
for (QWidget* widget : QApplication::topLevelWidgets()) {
if (widget->inherits("SendConfirmationDialog")) {
SendConfirmationDialog* dialog = qobject_cast<SendConfirmationDialog*>(widget);
@@ -33,8 +32,8 @@ void ConfirmSend()
button->click();
}
}
- });
- timer->start(0);
+ delete callback;
+ }), SLOT(call()));
}
//! Send coins to address and return txid.