mirror of
https://github.com/eosswedenorg/antelope-keygen
synced 2026-07-04 12:03:41 +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:
parent
8cb3fad9b1
commit
3c21e27f45
3 changed files with 13 additions and 32 deletions
|
|
@ -20,8 +20,8 @@ set( PROGRAM_SRC
|
||||||
add_executable( ${PROGRAM_EXE} ${PROGRAM_SRC} )
|
add_executable( ${PROGRAM_EXE} ${PROGRAM_SRC} )
|
||||||
|
|
||||||
# Libraries
|
# Libraries
|
||||||
find_package( Qt5 5.11 COMPONENTS Core Widgets REQUIRED )
|
find_package( Qt5 5.11 COMPONENTS Concurrent Core Widgets REQUIRED )
|
||||||
target_link_libraries( ${PROGRAM_EXE} Qt5::Core Qt5::Widgets common )
|
target_link_libraries( ${PROGRAM_EXE} Qt5::Concurrent Qt5::Core Qt5::Widgets common )
|
||||||
|
|
||||||
# --------------------------------
|
# --------------------------------
|
||||||
# Install
|
# Install
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,8 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
#include <QThread>
|
#include <QFuture>
|
||||||
|
#include <QtConcurrent>
|
||||||
#include <libeosio/WIF.h>
|
#include <libeosio/WIF.h>
|
||||||
#include <eoskeygen/core/leet.h>
|
#include <eoskeygen/core/leet.h>
|
||||||
#include <eoskeygen/core/string.h>
|
#include <eoskeygen/core/string.h>
|
||||||
|
|
@ -32,7 +33,6 @@
|
||||||
|
|
||||||
SearchWindow::SearchWindow(QWidget *parent, Qt::WindowFlags flags) :
|
SearchWindow::SearchWindow(QWidget *parent, Qt::WindowFlags flags) :
|
||||||
QWidget (parent, flags),
|
QWidget (parent, flags),
|
||||||
m_worker (NULL),
|
|
||||||
m_status ("status"),
|
m_status ("status"),
|
||||||
m_leet_cb ("L33t"),
|
m_leet_cb ("L33t"),
|
||||||
m_btn_exec ("Search"),
|
m_btn_exec ("Search"),
|
||||||
|
|
@ -86,21 +86,16 @@ m_btn_clear ("Clear")
|
||||||
m_txt_search.setFocus();
|
m_txt_search.setFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
SearchWindow::~SearchWindow()
|
|
||||||
{
|
|
||||||
// Make sure worker thread exits.
|
|
||||||
if (m_worker) {
|
|
||||||
m_worker->quit();
|
|
||||||
m_worker->wait();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SearchWindow::initSignals()
|
void SearchWindow::initSignals()
|
||||||
{
|
{
|
||||||
// Buttons
|
// Buttons
|
||||||
connect(&m_btn_exec, SIGNAL(released()), this, SLOT(search()));
|
connect(&m_btn_exec, SIGNAL(released()), this, SLOT(search()));
|
||||||
connect(&m_btn_clear, SIGNAL(released()), &m_output, SLOT(clear()));
|
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)));
|
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()
|
void SearchWindow::search()
|
||||||
{
|
{
|
||||||
if (m_worker && m_worker->isRunning()) {
|
if (m_worker.isRunning()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -162,16 +157,10 @@ void SearchWindow::search()
|
||||||
m_ksearch.addList(list);
|
m_ksearch.addList(list);
|
||||||
m_ksearch.setThreadCount(m_num_threads.value());
|
m_ksearch.setThreadCount(m_num_threads.value());
|
||||||
|
|
||||||
// Create search thread
|
QFuture<void> future = QtConcurrent::run(m_ksearch, &eoskeygen::KeySearch::find, m_num_results.value());
|
||||||
m_worker = QThread::create([this] {
|
m_worker.setFuture(future);
|
||||||
m_ksearch.find(m_num_results.value());
|
|
||||||
});
|
|
||||||
|
|
||||||
connect(m_worker, SIGNAL(started()), this, SLOT(searchStarted()));
|
|
||||||
connect(m_worker, SIGNAL(finished()), this, SLOT(searchFinished()));
|
|
||||||
|
|
||||||
m_status.setText("Searching for: " + QString::fromStdString(eoskeygen::strlist::join(list, ", ")));
|
m_status.setText("Searching for: " + QString::fromStdString(eoskeygen::strlist::join(list, ", ")));
|
||||||
m_worker->start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchWindow::output(const std::string& html)
|
void SearchWindow::output(const std::string& html)
|
||||||
|
|
@ -206,10 +195,4 @@ void SearchWindow::searchFinished()
|
||||||
m_btn_clear.setEnabled(true);
|
m_btn_clear.setEnabled(true);
|
||||||
m_num_threads.setEnabled(true);
|
m_num_threads.setEnabled(true);
|
||||||
m_num_results.setEnabled(true);
|
m_num_results.setEnabled(true);
|
||||||
|
|
||||||
// We are done with the worker pointer.
|
|
||||||
if (m_worker) {
|
|
||||||
delete m_worker;
|
|
||||||
m_worker = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,18 +31,16 @@
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
|
#include <QFutureWatcher>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <eoskeygen/key_search_result.h>
|
#include <eoskeygen/key_search_result.h>
|
||||||
#include <eoskeygen/key_search.h>
|
#include <eoskeygen/key_search.h>
|
||||||
|
|
||||||
class QThread;
|
|
||||||
|
|
||||||
class SearchWindow : public QWidget, public eoskeygen::IKeySearchResult
|
class SearchWindow : public QWidget, public eoskeygen::IKeySearchResult
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit SearchWindow(QWidget *parent = 0, Qt::WindowFlags flags = Qt::WindowFlags());
|
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);
|
void onResult(const struct libeosio::ec_keypair* key, const struct eoskeygen::KeySearch::result& result);
|
||||||
|
|
||||||
|
|
@ -70,7 +68,7 @@ signals:
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// Search worker thread.
|
// Search worker thread.
|
||||||
QThread* m_worker;
|
QFutureWatcher<void> m_worker;
|
||||||
|
|
||||||
eoskeygen::KeySearch m_ksearch;
|
eoskeygen::KeySearch m_ksearch;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue