Why should a removeSubWindow() raise exception?
Hi all,
my question tells for your very wide experience:
what are all the motivations for which a QMdiArea::removeSubWindow(QWidget* widget) should fail, raising an exception (and, so, crashing the program)?
Details:
MDI application.
QDialog as widget in a QMdiSubWindow.
When closing it, following rows are executed:
Code:
mdiArea->removeSubWindow(wArticle);
delete pArticle;
pArticle=NULL;
wArticle=NULL;
where:
mdiArea => QMdiArea*
wArticle => QMdiSubWindow*
pArticle => QDialog* (contained by wArticle)
The first of the four instructions raises an exception and makes crash the program.
So, what I'm asking is: what has wArticle to have of strange (since I checked it is not NULL) to make the method fail?
Re: Why should a removeSubWindow() raise exception?
Either pointer could be a dangling pointer. You could have forgotten to initialize it or it could've been already deleted (and forgot to nullify).
Re: Why should a removeSubWindow() raise exception?
Quote:
Originally Posted by
jpn
Either pointer could be a dangling pointer. You could have forgotten to initialize it or it could've been already deleted (and forgot to nullify).
Yes, I agree with you; maybe wArticle has been already deleted (probabily in a tricky way).
I read docs: so have I to delete wArticle after removing it from MdiArea, since it is not removed by removeSubWindow()? Is it right?
Re: Why should a removeSubWindow() raise exception?
Usually QMdiSubWindows have Qt::WA_DeleteOnClose set which means they'll get deleted upon close event.
Re: Why should a removeSubWindow() raise exception?
Quote:
Originally Posted by
jpn
Usually QMdiSubWindows have Qt::WA_DeleteOnClose set which means they'll get deleted upon close event.
Thank you, yes, now it is bright!
Update from the solving:
I tried to comment the row that raised the error (removeSubWindow()), and now everything works fine; I set the Qt::WA_DeleteOnClose so maybe when closing the window it got deleted, and when the method tried to remove it with the function, it found a deallocated memory: dump.
But now I'm wondering about the usefulness of the method removeSubWindow()... removing it, I don't risk memory lacks or something? The problem doesn't exist if what I just said is right, and DeleteOnClose works for it...
Anyway thank you very much,
you guru members make this forum unbeatable!
Re: Why should a removeSubWindow() raise exception?
I have another question that I think is related to this thread, so I didn't start a new one.
A Qt::WA_DeleteOnClose for a MdiSubWindow, when the subwindow get closed with event->accept() (in closeEvent()), deletes the QMdiSubWindow, or the QWidget inside it, or both of them??
Re: Why should a removeSubWindow() raise exception?
Quote:
Originally Posted by
Raccoon29
A Qt::WA_DeleteOnClose for a MdiSubWindow, when the subwindow get closed with event->accept() (in closeEvent()), deletes the QMdiSubWindow, or the QWidget inside it, or both of them??
If that attribute was set for MDI subwindow, it will delete the subwindow and all child widgets.
Re: Why should a removeSubWindow() raise exception?
Quote:
Originally Posted by
jacek
If that attribute was set for MDI subwindow, it will delete the subwindow and all child widgets.
Ok. Thank you jacek.