Crash after try to validate pointer
-
Hello. I 'm working on app which I will use to calculate some type of operations. I have dialog which is connected via signal/slot with his parent dialog. I have a lot of QWidgets on this dialog which are pointers. Some of them I initialise when I choose correct type of workplace. When I decide to choose for example "Cooperation" workplace, other QWidgets are initialise to nullptr. When I put some values to controls and click add button, the signal is emit and all data from all controls should go to the parent. However I have a problem with some widgets. When the object is not initialise (set to nullptr) I have a validation for this case. Below is the code of my signal which I call on add button:
void SimplyOperationDataDialog::on_addButton_pressed() { if(IsRequiredDataInserted()) { emit SendOperationData(GetWorkplaceName(),GetOperationName(),GetToolsQuantity(),GetOperationTime(),GetOperationDescription(), GetPreparationAndCompletionTime(),GetWorkplaceNumber(),GetWorkplaceCost(),GetUnitTime(), GetOperationClampingNumber(), GetOperationClampingData(), //Cooperation GetCooperationRateCurrency(),GetCooperationRateCurrencyCost(), GetCooperationUnitCurrency(),GetCooperationUnitCurrencyCost(), GetCooperationTotalCost(), //QualityControl GetQualityControlsMeasurementType(), GetQualityControlMeasurementTime(), GetQualityControlMeasurementEquipmentStatus(), //Marker GetMarkerFile(), GetMarkerTime(), //IronWorks //Assembly GetIronworksAssemblyType(), GetIronworksAssemblyTime(), //Packing GetIronworksPackingBoxType(), GetIronworksPackingBoxMaxQuantity(), GetIronworksPackingMaterial(), GetIronworksPackingTime(), //Drilling GetIronworksDrillingDrill(), GetIronworksDrillingMachine(), GetIronworksDrillingTime(), //Polishing GetIronworksPolishingAgent(), GetIronworksPolishingMaterial(), GetIronworksPolishingTime(), //Trovalization GetIronworksTrovalizationType(), GetIronworksTrovalizationAbrasiveAgent(), GetIronworksTrovalizationTime(), GetIronworksTrovalizationPartQuantity(), //Washing GetIronworksWashingAgent(), GetIronworksWashingTime(), //Conservation GetIronworksConservationAgent(), GetIronworksConservationTime()); CleanControls(); this->~SimplyOperationDataDialog(); } }
I have a problem with tho Getters: GetIronworksTrovalizationAbrasiveAgent() and GetIronworksTrovalizationTime(). During debugging my app crashes on one of them with error:
Below is the code which I use in both Getters:
QString SimplyOperationDataDialog::GetIronworksTrovalizationAbrasiveAgent() const { if(ironworksTrovalizationAbrasiveAgentComboBox != nullptr) { if(ironworksTrovalizationAbrasiveAgentComboBox->isEnabled()) { return ironworksTrovalizationAbrasiveAgentComboBox->currentText(); } else { return STR_EMPTY; } } else { return STR_EMPTY; } }
double SimplyOperationDataDialog::GetIronworksTrovalizationTime() const { if(ironworksTrovalizationTimeLineEdit!= nullptr) { if(ironworksTrovalizationTimeLineEdit->isEnabled()) { return ironworksTrovalizationTimeLineEdit->text().toDouble(); } else { return DBL_NULL; } } else { return DBL_NULL; } }
Both widget are set in constructor for nullptr. When I choose exact workplace they are initialise (new QCombobox()) or not.
So my question is: Why I got this error? Why I got error with attribute WS_Disabled? How can I solve it? Many thanks for any help.
Have a good day
BushyAxis793 -
Thanks everyone for help! I found a solution. I didn't check all pointers. Now it works!
-
@BushyAxis793 said in Crash after try to validate pointer:
During debugging my app crashes on one of them with error:
I don't actually see any crash. If/when it does crash, we need the stack trace window in the debugger.
It's your job to initialise all pointers to
nullptr
if necessary, and ensure what they point to is valid.Once you have this working you might like to rethink your signal parameters. Passing that many is not a good idea.
-
@BushyAxis793 said in Crash after try to validate pointer:
this->~SimplyOperationDataDialog();
call destructor directly?
this->~SimplyOperationDataDialog();
-
Thanks everyone for help! I found a solution. I didn't check all pointers. Now it works!
-