I’m currently trying to port my Qt application to Mac OSX and just came across the following problem:
One of my window classes (derived from QMainWindow) displays a dialog box when the close button is pressed, where you can save/discard changes or abort. This is done by reimplementing closeEvent as follows:
void ResultsWindow::closeEvent(QCloseEvent* event)
{
if (isWindowModified())
{
activateWindow();
QMessageBox::StandardButton button = QMessageBox::warning(
this,
APPLICATION_NAME,
"Warning: data have been modified. Do you want to save the "
"changes?",
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Abort,
QMessageBox::Abort);
switch (button)
{
case QMessageBox::Save:
if (!Save())
{
event->ignore();
return;
}
break;
case QMessageBox::Discard:
break;
case QMessageBox::Abort:
default:
event->ignore();
return;
}
}
event->accept();
}
The expected behavior is as follows: If you click “Abort”, the event is ignored and the window stays open. This works as expected on Linux and Windows. On OSX, however, the window is hidden, but still active in the background. What am I missing here? How can I make sure the window stays open?
Update:
I somehow think that this is a problem with Qt5. If the closeEvent method consists of nothing but event->ignore(); the window is still closed. I don’t think this is the intended behavior. Maybe I should post this problem to the Qt mailing list…
Update: This was a bug in Qt and is solved since version 5.1.