Skip to content

Commit 2b477e6

Browse files
committed
Merge #10098: Make qt wallet test compatible with qt4
e9a6461 Make qt wallet test compatible with qt4 (Russell Yanofsky) Tree-SHA512: a3e4598986cb3c5c20aaa1d440abc886d84fcc69a6ee4079787cfc8e3a2dce655060ff95612cb15ce8b5a9b8911e4afe2281345b59a4353ec32edf3771338381
2 parents fbf36ca + e9a6461 commit 2b477e6

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

src/Makefile.qt.include

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ QT_MOC_CPP = \
122122
qt/moc_bitcoinamountfield.cpp \
123123
qt/moc_bitcoingui.cpp \
124124
qt/moc_bitcoinunits.cpp \
125+
qt/moc_callback.cpp \
125126
qt/moc_clientmodel.cpp \
126127
qt/moc_coincontroldialog.cpp \
127128
qt/moc_coincontroltreewidget.cpp \
@@ -167,6 +168,7 @@ BITCOIN_MM = \
167168
QT_MOC = \
168169
qt/bitcoin.moc \
169170
qt/bitcoinamountfield.moc \
171+
qt/callback.moc \
170172
qt/intro.moc \
171173
qt/overviewpage.moc \
172174
qt/rpcconsole.moc
@@ -189,6 +191,7 @@ BITCOIN_QT_H = \
189191
qt/bitcoinamountfield.h \
190192
qt/bitcoingui.h \
191193
qt/bitcoinunits.h \
194+
qt/callback.h \
192195
qt/clientmodel.h \
193196
qt/coincontroldialog.h \
194197
qt/coincontroltreewidget.h \

src/qt/callback.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#ifndef BITCOIN_QT_CALLBACK_H
2+
#define BITCOIN_QT_CALLBACK_H
3+
4+
#include <QObject>
5+
6+
class Callback : public QObject
7+
{
8+
Q_OBJECT
9+
public Q_SLOTS:
10+
virtual void call() = 0;
11+
};
12+
13+
template <typename F>
14+
class FunctionCallback : public Callback
15+
{
16+
F f;
17+
18+
public:
19+
FunctionCallback(F f_) : f(std::move(f_)) {}
20+
~FunctionCallback() override {}
21+
void call() override { f(this); }
22+
};
23+
24+
template <typename F>
25+
FunctionCallback<F>* makeCallback(F f)
26+
{
27+
return new FunctionCallback<F>(std::move(f));
28+
}
29+
30+
#endif // BITCOIN_QT_CALLBACK_H

src/qt/test/wallettests.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "wallettests.h"
22

33
#include "qt/bitcoinamountfield.h"
4+
#include "qt/callback.h"
45
#include "qt/optionsmodel.h"
56
#include "qt/platformstyle.h"
67
#include "qt/qvalidatedlineedit.h"
@@ -22,9 +23,7 @@ namespace
2223
//! Press "Yes" button in modal send confirmation dialog.
2324
void ConfirmSend()
2425
{
25-
QTimer* timer = new QTimer;
26-
timer->setSingleShot(true);
27-
QObject::connect(timer, &QTimer::timeout, []() {
26+
QTimer::singleShot(0, makeCallback([](Callback* callback) {
2827
for (QWidget* widget : QApplication::topLevelWidgets()) {
2928
if (widget->inherits("SendConfirmationDialog")) {
3029
SendConfirmationDialog* dialog = qobject_cast<SendConfirmationDialog*>(widget);
@@ -33,8 +32,8 @@ void ConfirmSend()
3332
button->click();
3433
}
3534
}
36-
});
37-
timer->start(0);
35+
delete callback;
36+
}), SLOT(call()));
3837
}
3938

4039
//! Send coins to address and return txid.

0 commit comments

Comments
 (0)