PDA

View Full Version : How to close a local QDialog?



MorrisLiang
23rd August 2010, 06:42
My application shows an icon in system tray which allows user to quit the application. Sometimes, my app will popup a dialog to let user verify.



void MyWidget::showWarning()
{
QDialog dialog;
...
...
int result = dialog.exec();
if(result == QDialog::Accepted)
{
...
}
}


The problem is, if the local QDialog object is executing when user quits the app.MyWidget will be deleted before the line
if(result == QDialog::Accepted) is called, which makes the app crash.

So, how do I safely finish the QDialog when the user quits the app?

aamer4yu
23rd August 2010, 07:19
Which version are you using ? I somewhat remember this was a bug in Qt..
anyway you can try catching QCoreApplication::aboutToQuit and closing the dialog yourself :-)

MorrisLiang
23rd August 2010, 10:19
Which version are you using ? I somewhat remember this was a bug in Qt..
anyway you can try catching QCoreApplication::aboutToQuit and closing the dialog yourself :-)

I'm using 4.6. Well, I will try that. Thanks~