gfunk
16th October 2007, 19:22
It seems that when I implement the QMainWindow::closeEvent() function, my application blocks shutdown -ie, when I shutdown the computer, it tries to close all the apps but chokes on my Qt app, and so it doesn't shut down. In my closeEvent() function I do create a QMessageBox to ask the user if it's okay to exit. When I remove this QMessageBox out, my app closes on shutdown correctly along with the rest of system. Wondering what might be wrong with my code...
mpMessageBox = new QMessageBox(QMessageBox::Question, "Name",
QString(tr("Are you sure you want to exit?")),
QMessageBox::Yes | QMessageBox::No, this);
mpMessageBox->setModal(true);
mpMessageBox->setAttribute(Qt::WA_DeleteOnClose);
mpMessageBox->show();
connect(mpMessageBox, SIGNAL(destroyed()), this, SLOT(dismissMsgBox()));
Yes, I know it's rather unorthodox to create a message box like this, but it was just so that it would not block the event loop, while still having a modal dialog.
mpMessageBox = new QMessageBox(QMessageBox::Question, "Name",
QString(tr("Are you sure you want to exit?")),
QMessageBox::Yes | QMessageBox::No, this);
mpMessageBox->setModal(true);
mpMessageBox->setAttribute(Qt::WA_DeleteOnClose);
mpMessageBox->show();
connect(mpMessageBox, SIGNAL(destroyed()), this, SLOT(dismissMsgBox()));
Yes, I know it's rather unorthodox to create a message box like this, but it was just so that it would not block the event loop, while still having a modal dialog.