From 3c67f5a15d798e92497fbdd8eb0252ad368d9576 Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Tue, 18 Dec 2018 12:55:11 -0500 Subject: [PATCH] capturing this by ref is dumb --- GUI/extenwindow.cpp | 4 ++-- GUI/mainwindow.cpp | 26 ++++++++++---------------- GUI/mainwindow.h | 1 - GUI/setdialog.cpp | 2 +- 4 files changed, 13 insertions(+), 20 deletions(-) diff --git a/GUI/extenwindow.cpp b/GUI/extenwindow.cpp index c939ea4..b60be4f 100644 --- a/GUI/extenwindow.cpp +++ b/GUI/extenwindow.cpp @@ -83,8 +83,8 @@ ExtenWindow::ExtenWindow(QWidget* parent) : ui->extenList->installEventFilter(this); - connect(ui->addButton, &QPushButton::clicked, [&] { Add(QFileDialog::getOpenFileName(this, SELECT_EXTENSION, "C:\\", EXTENSION_FILES)); }); - connect(ui->rmvButton, &QPushButton::clicked, [&] { if (auto extenName = ui->extenList->currentItem()) Unload(extenName->text()); Sync(); }); + connect(ui->addButton, &QPushButton::clicked, [this] { Add(QFileDialog::getOpenFileName(this, SELECT_EXTENSION, "C:\\", EXTENSION_FILES)); }); + connect(ui->rmvButton, &QPushButton::clicked, [this] { if (auto extenName = ui->extenList->currentItem()) Unload(extenName->text()); Sync(); }); for (auto extenName : QString(QAutoFile(EXTEN_SAVE_FILE, QIODevice::ReadOnly)->readAll()).split(">")) Load(extenName); Sync(); diff --git a/GUI/mainwindow.cpp b/GUI/mainwindow.cpp index 60b41c1..8372f31 100644 --- a/GUI/mainwindow.cpp +++ b/GUI/mainwindow.cpp @@ -43,11 +43,11 @@ MainWindow::MainWindow(QWidget *parent) : settings.sync(); Host::Start( - [&](DWORD processId) { ProcessConnected(processId); }, - [&](DWORD processId) { ProcessDisconnected(processId); }, - [&](TextThread* thread) { ThreadAdded(thread); }, - [&](TextThread* thread) { ThreadRemoved(thread); }, - [&](TextThread* thread, std::wstring& output) { return SentenceReceived(thread, output); } + [this](DWORD processId) { ProcessConnected(processId); }, + [this](DWORD processId) { ProcessDisconnected(processId); }, + [this](TextThread* thread) { ThreadAdded(thread); }, + [this](TextThread* thread) { ThreadRemoved(thread); }, + [this](TextThread* thread, std::wstring& output) { return SentenceReceived(thread, output); } ); Host::AddConsoleOutput(ABOUT); @@ -83,16 +83,10 @@ void MainWindow::closeEvent(QCloseEvent*) QCoreApplication::quit(); // Need to do this to kill any windows that might've been made by extensions } - -void MainWindow::InvokeOnMainThread(std::function f) -{ - QMetaObject::invokeMethod(this, f); -} - void MainWindow::ProcessConnected(DWORD processId) { if (processId == 0) return; - InvokeOnMainThread([&, processId] + QMetaObject::invokeMethod(this, [this, processId] { QString process = S(Util::GetModuleFileName(processId).value()); ui->processCombo->addItem(QString::number(processId, 16).toUpper() + ": " + QFileInfo(process).fileName()); @@ -108,19 +102,19 @@ void MainWindow::ProcessConnected(DWORD processId) void MainWindow::ProcessDisconnected(DWORD processId) { - InvokeOnMainThread([&, processId] { ui->processCombo->removeItem(ui->processCombo->findText(QString::number(processId, 16).toUpper() + ":", Qt::MatchStartsWith)); }); + QMetaObject::invokeMethod(this, [this, processId] { ui->processCombo->removeItem(ui->processCombo->findText(QString::number(processId, 16).toUpper() + ":", Qt::MatchStartsWith)); }); } void MainWindow::ThreadAdded(TextThread* thread) { QString ttString = TextThreadString(thread) + S(thread->name) + " (" + GenerateCode(thread->hp, thread->tp.processId) + ")"; - InvokeOnMainThread([&, ttString] { ui->ttCombo->addItem(ttString); }); + QMetaObject::invokeMethod(this, [this, ttString] { ui->ttCombo->addItem(ttString); }); } void MainWindow::ThreadRemoved(TextThread* thread) { QString ttString = TextThreadString(thread); - InvokeOnMainThread([&, ttString] + QMetaObject::invokeMethod(this, [this, ttString] { int threadIndex = ui->ttCombo->findText(ttString, Qt::MatchStartsWith); if (threadIndex == ui->ttCombo->currentIndex()) @@ -138,7 +132,7 @@ bool MainWindow::SentenceReceived(TextThread* thread, std::wstring& sentence) { sentence += L"\r\n"; QString ttString = TextThreadString(thread); - InvokeOnMainThread([&, ttString, sentence] + QMetaObject::invokeMethod(this, [this, ttString, sentence] { if (ui->ttCombo->currentText().startsWith(ttString)) { diff --git a/GUI/mainwindow.h b/GUI/mainwindow.h index a80dfa4..242fbb3 100644 --- a/GUI/mainwindow.h +++ b/GUI/mainwindow.h @@ -17,7 +17,6 @@ public: private: void closeEvent(QCloseEvent*) override; - void InvokeOnMainThread(std::function f); void ProcessConnected(DWORD processId); void ProcessDisconnected(DWORD processId); void ThreadAdded(TextThread* thread); diff --git a/GUI/setdialog.cpp b/GUI/setdialog.cpp index af212dc..01d9688 100644 --- a/GUI/setdialog.cpp +++ b/GUI/setdialog.cpp @@ -21,7 +21,7 @@ SetDialog::SetDialog(QWidget* parent) : ui->layout->insertRow(0, label, spinBox); } - connect(ui->buttonBox, &QDialogButtonBox::accepted, [&] { edited = true; }); + connect(ui->buttonBox, &QDialogButtonBox::accepted, [this] { edited = true; }); } SetDialog::~SetDialog()