mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 04:52:59 +01:00
Make qt wallet test compatible with qt4
Unlike Qt5, the Qt4 signals implementation doesn't allow a signal to be directly connected to a c++ lambda expression. Work around this by defining a Callback QObject with a virtual method that can forward calls to a closure. The Qt4 error was reported by Patrick Strateman <patrick.strateman@gmail.com> in https://github.com/bitcoin/bitcoin/pull/10039#issuecomment-289248763
This commit is contained in:
parent
919aaf6508
commit
e9a64615c8
@ -122,6 +122,7 @@ QT_MOC_CPP = \
|
|||||||
qt/moc_bitcoinamountfield.cpp \
|
qt/moc_bitcoinamountfield.cpp \
|
||||||
qt/moc_bitcoingui.cpp \
|
qt/moc_bitcoingui.cpp \
|
||||||
qt/moc_bitcoinunits.cpp \
|
qt/moc_bitcoinunits.cpp \
|
||||||
|
qt/moc_callback.cpp \
|
||||||
qt/moc_clientmodel.cpp \
|
qt/moc_clientmodel.cpp \
|
||||||
qt/moc_coincontroldialog.cpp \
|
qt/moc_coincontroldialog.cpp \
|
||||||
qt/moc_coincontroltreewidget.cpp \
|
qt/moc_coincontroltreewidget.cpp \
|
||||||
@ -167,6 +168,7 @@ BITCOIN_MM = \
|
|||||||
QT_MOC = \
|
QT_MOC = \
|
||||||
qt/bitcoin.moc \
|
qt/bitcoin.moc \
|
||||||
qt/bitcoinamountfield.moc \
|
qt/bitcoinamountfield.moc \
|
||||||
|
qt/callback.moc \
|
||||||
qt/intro.moc \
|
qt/intro.moc \
|
||||||
qt/overviewpage.moc \
|
qt/overviewpage.moc \
|
||||||
qt/rpcconsole.moc
|
qt/rpcconsole.moc
|
||||||
@ -189,6 +191,7 @@ BITCOIN_QT_H = \
|
|||||||
qt/bitcoinamountfield.h \
|
qt/bitcoinamountfield.h \
|
||||||
qt/bitcoingui.h \
|
qt/bitcoingui.h \
|
||||||
qt/bitcoinunits.h \
|
qt/bitcoinunits.h \
|
||||||
|
qt/callback.h \
|
||||||
qt/clientmodel.h \
|
qt/clientmodel.h \
|
||||||
qt/coincontroldialog.h \
|
qt/coincontroldialog.h \
|
||||||
qt/coincontroltreewidget.h \
|
qt/coincontroltreewidget.h \
|
||||||
|
30
src/qt/callback.h
Normal file
30
src/qt/callback.h
Normal file
@ -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
|
@ -1,6 +1,7 @@
|
|||||||
#include "wallettests.h"
|
#include "wallettests.h"
|
||||||
|
|
||||||
#include "qt/bitcoinamountfield.h"
|
#include "qt/bitcoinamountfield.h"
|
||||||
|
#include "qt/callback.h"
|
||||||
#include "qt/optionsmodel.h"
|
#include "qt/optionsmodel.h"
|
||||||
#include "qt/platformstyle.h"
|
#include "qt/platformstyle.h"
|
||||||
#include "qt/qvalidatedlineedit.h"
|
#include "qt/qvalidatedlineedit.h"
|
||||||
@ -22,9 +23,7 @@ namespace
|
|||||||
//! Press "Yes" button in modal send confirmation dialog.
|
//! Press "Yes" button in modal send confirmation dialog.
|
||||||
void ConfirmSend()
|
void ConfirmSend()
|
||||||
{
|
{
|
||||||
QTimer* timer = new QTimer;
|
QTimer::singleShot(0, makeCallback([](Callback* callback) {
|
||||||
timer->setSingleShot(true);
|
|
||||||
QObject::connect(timer, &QTimer::timeout, []() {
|
|
||||||
for (QWidget* widget : QApplication::topLevelWidgets()) {
|
for (QWidget* widget : QApplication::topLevelWidgets()) {
|
||||||
if (widget->inherits("SendConfirmationDialog")) {
|
if (widget->inherits("SendConfirmationDialog")) {
|
||||||
SendConfirmationDialog* dialog = qobject_cast<SendConfirmationDialog*>(widget);
|
SendConfirmationDialog* dialog = qobject_cast<SendConfirmationDialog*>(widget);
|
||||||
@ -33,8 +32,8 @@ void ConfirmSend()
|
|||||||
button->click();
|
button->click();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
delete callback;
|
||||||
timer->start(0);
|
}), SLOT(call()));
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Send coins to address and return txid.
|
//! Send coins to address and return txid.
|
||||||
|
Loading…
Reference in New Issue
Block a user