Hi,
I have a QMainWindow subclass with the attribute Qt::WA_DeleteOnClose set.
In some cases, I open a QDialog (and more exactly QWizard) that is a child of QMainWindow.
If the user interact with a particular QAction from the systray icon, I close the QMainWindow subclass programatically. The problem is after the call to the QMainWindow destructor, the control flow returned right after the QWizard exec call :
if(wizard)
{
if(wizard->exec())
{
if(wizard->field("displayListing").toBool())
{
setRootIndex(listingIndex);
show();
}
}
delete wizard;
wizard = 0;
}
if(wizard)
{
if(wizard->exec())
{
if(wizard->field("displayListing").toBool())
{
setRootIndex(listingIndex);
show();
}
}
delete wizard;
wizard = 0;
}
To copy to clipboard, switch view to plain text mode
So in this particular case, delete wizard failed and I have a crash. Moreover, it is silly than some code class code could still be executed after the destruction of the object !!!
I have a solution (hope it could help) but I would like to know if there is a better way to deal with it.
Here is my solution by overidding the close() slot of the QMainWindow :
void MyWindow::close()
{
if(wizard)
{
closeRequested = true;
wizard->reject();
}
else
{
}
}
void MyWindow::close()
{
if(wizard)
{
closeRequested = true;
wizard->reject();
}
else
{
QMainWindow::close();
}
}
To copy to clipboard, switch view to plain text mode
So if the wizard pointer is not null, i set a member boolean variable to true and I programatically reject the dialog rather than propagating the close() call to the parent (QMainWindow) classe.
Then, the control returned right after the wizard->exec() call, I can safely destroy it and it test the boolean just after and do my close() call then.
Do you think there is a much cleaner solution ?
Bookmarks