OptionsDialog: fixed memleak

Hold thread as member so the lifetime of it is handled by the dialog.
Another option would be a std::unique_ptr.
This commit is contained in:
ballessay 2017-04-01 00:47:37 +02:00
parent df72be09a5
commit c42faba81c
2 changed files with 10 additions and 11 deletions

View File

@ -8,7 +8,8 @@
OptionsDialog::OptionsDialog(QWidget *parent):
QDialog(parent),
ui(new Ui::OptionsDialog)
ui(new Ui::OptionsDialog),
analThread(this)
{
this->core = new QRCore();
this->anal_level = 0;
@ -39,6 +40,8 @@ OptionsDialog::OptionsDialog(QWidget *parent):
// Add this so the dialog resizes when widgets are shown/hidden
//this->layout()->setSizeConstraint(QLayout::SetFixedSize);
connect(&analThread, SIGNAL(finished()), this, SLOT(anal_finished()));
}
OptionsDialog::~OptionsDialog()
@ -169,18 +172,14 @@ void OptionsDialog::on_okButton_clicked()
ui->statusLabel->setText("Analysis in progress");
// Threads stuff
// create an instance of MyThread
this->analThread = new AnalThread(w);
// connect signal/slot
connect(analThread, SIGNAL(finished()), this, SLOT(anal_finished()));
//analThread->level = anal_level;
int level = 0;
if (anal_level == true) {
analThread->level = ui->analSlider->value();
} else {
analThread->level = 0;
level = ui->analSlider->value();
}
analThread->start();
analThread.start(core, level);
}
void OptionsDialog::anal_finished()

View File

@ -43,7 +43,7 @@ private:
QString filename;
QString shortfn;
Ui::OptionsDialog *ui;
AnalThread *analThread;
AnalThread analThread;
MainWindow *w;
};