+ 1

QT dialog c++ Crash on Close button

Hi I have added a push button to dialog and doing below: closeButton->OnClick().Connect(this, &myclass::OnCloseButtonClick); Close button click: if (p_dialog) { p_dialog->Close(); auto otherDialog = _other; delete p_dialog; p_dialog = nullptr; otherDialog ->Show(); } Above works fine. If I want to perform same action (close current and open other dialog after releasing memory from current dialog) to default close button , it crashes. Below code causes crash: p_dialog->OnAboutToClose().Connect(this, &myclass::OnDialogClose); //on dialog close if (p_dialog) { //p_dialog->Close(); auto otherDialog = _other; delete p_dialog; p_dialog = nullptr; otherDialog ->Show(); } both slots are same apart from the fact that close is commented. Any hint on why it is crashing?

17th Jul 2024, 7:07 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
9 Answers
+ 1
you can use debugger to see why and where it crash. It is probably crash internally inside a p_dialog function because is still running some code on other thread and you free the memory without closed it properly
18th Jul 2024, 5:58 AM
john ds
john ds - avatar
0
in your code below, you commented out //p->dialog->Close(); but you did not comment out delete p_dialog; and p_dialog = nullptr;
17th Jul 2024, 10:42 AM
Bob_Li
Bob_Li - avatar
0
Hi Is it not necessary to delete the dialog? I had not commented it out as it was not calling destructor of dialog without those lines.
17th Jul 2024, 12:41 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
0
maybe you just need to close the dialog instead of deleting and setting it to nullptr? I'm not sure how you set it up but maybe there is a hidden dependency between the otherDialog and your p_dialog? or maybe put the otherDialog->Show(); above the p_dialog destructors?
17th Jul 2024, 1:56 PM
Bob_Li
Bob_Li - avatar
0
Close button closes the current dialogue for sure. no need to close the same. Apart from that, there is no dependency between two dialogs.
17th Jul 2024, 3:57 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
0
maybe others have a better suggestion. Incomplete info can only be answered with guesses at best ...
17th Jul 2024, 4:13 PM
Bob_Li
Bob_Li - avatar
0
My dialog is of type qdockwidget . What should I do to get the control once × is clicked on dialogue
17th Jul 2024, 4:23 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
17th Jul 2024, 5:11 PM
Bob_Li
Bob_Li - avatar
0
Yes, it's crashing in hide
18th Jul 2024, 6:15 AM
Ketan Lalcheta
Ketan Lalcheta - avatar