1
0
Fork 0
mirror of https://github.com/eosswedenorg/antelope-keygen synced 2026-06-17 03:50:03 +02:00

gui/SearchWindow: Use QFutureWatcher instead of QThread.

By removing the call to QThread::create() that requires version >= 5.11 we can have a lower version as requirement.

This is useful because a lot of systems don't ship with 5.11 as default.
This commit is contained in:
Henrik Hautakoski 2020-04-10 10:45:19 +02:00
parent 8cb3fad9b1
commit 3c21e27f45
3 changed files with 13 additions and 32 deletions

View file

@ -20,8 +20,8 @@ set( PROGRAM_SRC
add_executable( ${PROGRAM_EXE} ${PROGRAM_SRC} )
# Libraries
find_package( Qt5 5.11 COMPONENTS Core Widgets REQUIRED )
target_link_libraries( ${PROGRAM_EXE} Qt5::Core Qt5::Widgets common )
find_package( Qt5 5.11 COMPONENTS Concurrent Core Widgets REQUIRED )
target_link_libraries( ${PROGRAM_EXE} Qt5::Concurrent Qt5::Core Qt5::Widgets common )
# --------------------------------
# Install

View file

@ -24,7 +24,8 @@
#include <QDebug>
#include <QMessageBox>
#include <QGridLayout>
#include <QThread>
#include <QFuture>
#include <QtConcurrent>
#include <libeosio/WIF.h>
#include <eoskeygen/core/leet.h>
#include <eoskeygen/core/string.h>
@ -32,7 +33,6 @@
SearchWindow::SearchWindow(QWidget *parent, Qt::WindowFlags flags) :
QWidget (parent, flags),
m_worker (NULL),
m_status ("status"),
m_leet_cb ("L33t"),
m_btn_exec ("Search"),
@ -86,21 +86,16 @@ m_btn_clear ("Clear")
m_txt_search.setFocus();
}
SearchWindow::~SearchWindow()
{
// Make sure worker thread exits.
if (m_worker) {
m_worker->quit();
m_worker->wait();
}
}
void SearchWindow::initSignals()
{
// Buttons
connect(&m_btn_exec, SIGNAL(released()), this, SLOT(search()));
connect(&m_btn_clear, SIGNAL(released()), &m_output, SLOT(clear()));
// Worker Thread
connect(&m_worker, SIGNAL(started()), this, SLOT(searchStarted()));
connect(&m_worker, SIGNAL(finished()), this, SLOT(searchFinished()));
connect(this, SIGNAL(addOutput(QString)), this, SLOT(output(QString)));
}
@ -137,7 +132,7 @@ void SearchWindow::onResult(const struct libeosio::ec_keypair* key, const struct
void SearchWindow::search()
{
if (m_worker && m_worker->isRunning()) {
if (m_worker.isRunning()) {
return;
}
@ -162,16 +157,10 @@ void SearchWindow::search()
m_ksearch.addList(list);
m_ksearch.setThreadCount(m_num_threads.value());
// Create search thread
m_worker = QThread::create([this] {
m_ksearch.find(m_num_results.value());
});
connect(m_worker, SIGNAL(started()), this, SLOT(searchStarted()));
connect(m_worker, SIGNAL(finished()), this, SLOT(searchFinished()));
QFuture<void> future = QtConcurrent::run(m_ksearch, &eoskeygen::KeySearch::find, m_num_results.value());
m_worker.setFuture(future);
m_status.setText("Searching for: " + QString::fromStdString(eoskeygen::strlist::join(list, ", ")));
m_worker->start();
}
void SearchWindow::output(const std::string& html)
@ -206,10 +195,4 @@ void SearchWindow::searchFinished()
m_btn_clear.setEnabled(true);
m_num_threads.setEnabled(true);
m_num_results.setEnabled(true);
// We are done with the worker pointer.
if (m_worker) {
delete m_worker;
m_worker = NULL;
}
}

View file

@ -31,18 +31,16 @@
#include <QLineEdit>
#include <QCheckBox>
#include <QGridLayout>
#include <QFutureWatcher>
#include <QWidget>
#include <eoskeygen/key_search_result.h>
#include <eoskeygen/key_search.h>
class QThread;
class SearchWindow : public QWidget, public eoskeygen::IKeySearchResult
{
Q_OBJECT
public:
explicit SearchWindow(QWidget *parent = 0, Qt::WindowFlags flags = Qt::WindowFlags());
virtual ~SearchWindow();
void onResult(const struct libeosio::ec_keypair* key, const struct eoskeygen::KeySearch::result& result);
@ -70,7 +68,7 @@ signals:
private:
// Search worker thread.
QThread* m_worker;
QFutureWatcher<void> m_worker;
eoskeygen::KeySearch m_ksearch;