mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
Fix memory leak in download-from-dive-computer widget
Instead of (re)allocating the vendor and product models, use the setStringList method on sub objects. Even though only a theoretical problem, the model objects are moved in front of the ui object, so that the widgets referencing the models are destroyed first. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
35c5016777
commit
efabf0a55c
2 changed files with 8 additions and 17 deletions
|
@ -24,8 +24,6 @@ namespace DownloadFromDcGlobal {
|
|||
DownloadFromDCWidget::DownloadFromDCWidget(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f),
|
||||
downloading(false),
|
||||
previousLast(0),
|
||||
vendorModel(0),
|
||||
productModel(0),
|
||||
timer(new QTimer(this)),
|
||||
dumpWarningShown(false),
|
||||
ostcFirmwareCheck(0),
|
||||
|
@ -33,7 +31,7 @@ DownloadFromDCWidget::DownloadFromDCWidget(QWidget *parent, Qt::WindowFlags f) :
|
|||
{
|
||||
diveImportedModel = new DiveImportedModel(this);
|
||||
diveImportedModel->setDiveTable(&downloadTable);
|
||||
vendorModel = new QStringListModel(vendorList);
|
||||
vendorModel.setStringList(vendorList);
|
||||
QShortcut *close = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this);
|
||||
QShortcut *quit = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this);
|
||||
|
||||
|
@ -54,7 +52,8 @@ DownloadFromDCWidget::DownloadFromDCWidget(QWidget *parent, Qt::WindowFlags f) :
|
|||
ui.chooseLogFile->setEnabled(ui.logToFile->isChecked());
|
||||
ui.selectAllButton->setEnabled(false);
|
||||
ui.unselectAllButton->setEnabled(false);
|
||||
ui.vendor->setModel(vendorModel);
|
||||
ui.vendor->setModel(&vendorModel);
|
||||
ui.product->setModel(&productModel);
|
||||
|
||||
progress_bar_text = "";
|
||||
|
||||
|
@ -81,8 +80,7 @@ DownloadFromDCWidget::DownloadFromDCWidget(QWidget *parent, Qt::WindowFlags f) :
|
|||
auto dc = SettingsObjectWrapper::instance()->dive_computer_settings;
|
||||
if (!dc->dc_vendor().isEmpty()) {
|
||||
ui.vendor->setCurrentIndex(ui.vendor->findText(dc->dc_vendor()));
|
||||
productModel = new QStringListModel(productList[dc->dc_vendor()]);
|
||||
ui.product->setModel(productModel);
|
||||
productModel.setStringList(productList[dc->dc_vendor()]);
|
||||
if (!dc->dc_product().isEmpty())
|
||||
ui.product->setCurrentIndex(ui.product->findText(dc->dc_product()));
|
||||
}
|
||||
|
@ -241,19 +239,12 @@ void DownloadFromDCWidget::updateState(states state)
|
|||
void DownloadFromDCWidget::on_vendor_currentIndexChanged(const QString &vendor)
|
||||
{
|
||||
int dcType = DC_TYPE_SERIAL;
|
||||
QAbstractItemModel *currentModel = ui.product->model();
|
||||
if (!currentModel)
|
||||
return;
|
||||
|
||||
productModel = new QStringListModel(productList[vendor]);
|
||||
ui.product->setModel(productModel);
|
||||
productModel.setStringList(productList[vendor]);
|
||||
ui.product->setCurrentIndex(0);
|
||||
|
||||
if (vendor == QString("Uemis"))
|
||||
dcType = DC_TYPE_UEMIS;
|
||||
fill_device_list(dcType);
|
||||
|
||||
// Memleak - but deleting gives me a crash.
|
||||
//currentModel->deleteLater();
|
||||
}
|
||||
|
||||
void DownloadFromDCWidget::on_product_currentIndexChanged(const QString &product)
|
||||
|
|
|
@ -60,14 +60,14 @@ private:
|
|||
void markChildrenAsEnabled();
|
||||
void updateDeviceEnabled();
|
||||
|
||||
QStringListModel vendorModel;
|
||||
QStringListModel productModel;
|
||||
Ui::DownloadFromDiveComputer ui;
|
||||
DownloadThread thread;
|
||||
bool downloading;
|
||||
|
||||
int previousLast;
|
||||
|
||||
QStringListModel *vendorModel;
|
||||
QStringListModel *productModel;
|
||||
void fill_device_list(int dc_type);
|
||||
QTimer *timer;
|
||||
bool dumpWarningShown;
|
||||
|
|
Loading…
Reference in a new issue