Pārlūkot izejas kodu

created safeguard against assigning validator to nonexistent line edit

fiffty-50 4 gadi atpakaļ
vecāks
revīzija
d28cf1760b
2 mainītis faili ar 14 papildinājumiem un 4 dzēšanām
  1. 7 2
      src/gui/dialogues/newpilot.cpp
  2. 7 2
      src/gui/widgets/settingswidget.cpp

+ 7 - 2
src/gui/dialogues/newpilot.cpp

@@ -81,10 +81,15 @@ void NewPilot::on_buttonBox_accepted()
 
 void NewPilot::setupValidators()
 {
+    DEB("Setting up Validators...");
     for(const auto& pair : LINE_EDIT_VALIDATORS){
         auto line_edit = parent()->findChild<QLineEdit*>(pair.first);
-        auto validator = new QRegularExpressionValidator(pair.second,line_edit);
-        line_edit->setValidator(validator);
+        if(line_edit != nullptr){
+            auto validator = new QRegularExpressionValidator(pair.second,line_edit);
+            line_edit->setValidator(validator);
+        }else{
+            DEB("Error: Line Edit not found: "<< pair.first << " - skipping.");
+        }
     }
 }
 

+ 7 - 2
src/gui/widgets/settingswidget.cpp

@@ -113,8 +113,13 @@ void SettingsWidget::setupValidators()
     DEB("Setting up Validators...");
     for(const auto& pair : LINE_EDIT_VALIDATORS){
         auto line_edit = parent()->findChild<QLineEdit*>(pair.first);
-        auto validator = new QRegularExpressionValidator(pair.second,line_edit);
-        line_edit->setValidator(validator);
+        if(line_edit != nullptr){
+            auto validator = new QRegularExpressionValidator(pair.second,line_edit);
+            line_edit->setValidator(validator);
+        }else{
+            DEB("Error: Line Edit not found: "<< pair.first << " - skipping.");
+        }
+
     }
 }