浏览代码

memory management in pilotsWidget

fiffty-50 4 年之前
父节点
当前提交
9941a6ee9d
共有 1 个文件被更改,包括 10 次插入11 次删除
  1. 10 11
      src/gui/widgets/pilotswidget.cpp

+ 10 - 11
src/gui/widgets/pilotswidget.cpp

@@ -58,7 +58,6 @@ void PilotsWidget::tableView_selectionChanged()//const QItemSelection &index, co
             delete np;
         }
     }
-
 }
 
 void PilotsWidget::tableView_headerClicked(int column)
@@ -83,15 +82,15 @@ void PilotsWidget::on_deletePushButton_clicked()
     if(selectedPilots.length() == 1){
         for(const auto& selectedPilot : selectedPilots){
             if (selectedPilot > 0) {
-                auto pil = new Pilot(selectedPilot);
-                if(!pil->remove()) {
+                auto pil = Pilot(selectedPilot);
+                if(!pil.remove()) {
                     QVector<QString> columns = {"doft","dept","dest"};
                     QVector<QString> details = Db::multiSelect(columns, "flights", "pic",
                                                                QString::number(selectedPilot), Db::exactMatch);
-                    auto mb = new QMessageBox(this);
+                    auto mb = QMessageBox(this);
                     QString message = "\nUnable to delete. The following error has ocurred:\n\n";
                     if(!details.isEmpty()){
-                        message += pil->error + QLatin1String("\n\n");
+                        message += pil.error + QLatin1String("\n\n");
                         message += "This is most likely the case because a flight exists with the Pilot "
                                    "you are trying to delete. You have to change or remove this flight "
                                    "before being able to remove this pilot from the database.\n\n"
@@ -103,17 +102,17 @@ void PilotsWidget::on_deletePushButton_clicked()
                                     + details[i+2] + QLatin1String("\n");
                         }
                     }
-                    mb->setText(message);
-                    mb->setIcon(QMessageBox::Critical);
-                    mb->show();
+                    mb.setText(message);
+                    mb.setIcon(QMessageBox::Critical);
+                    mb.exec();
                 }
             }
         }
         refreshModelAndView();
     } else {
-        auto mb = new QMessageBox(this);
-        mb->setText("No Pilot selected.");
-        mb->show();
+        auto mb = QMessageBox(this);
+        mb.setText("No Pilot selected.");
+        mb.show();
     }
 }