PDA

View Full Version : Application crasches due to QMessageBox if hidden



dobedidoo
9th December 2009, 13:08
In my application I use a QSystemTray which enables me to hide ("minimize to tray") my main window, without closing it (the system tray icon is available for action).

Now I've noticed that if I use an action from the system tray icon's context menu to display a regular QMessageBox (eg. a standard information box with only an 'OK' button) when the main window is hidden (that is, I've called hide() from my main window), then my application crashes when I click the 'OK' button in the QMessageBox.

If the main window is not hidden, then all works fine.

Any ideas how I should prevent this crash?

I'm using Qt 4.4.3.

------------

Additional comment:
The following code causes a crash:

void MainWindow::trayIconMessageClicked()
{
QMessageBox box(QMessageBox::Information, "MyApp", "The message...", QMessageBox::Ok);
box.setWindowIcon(box.iconPixmap());
box.exec();
}
while the following apparently does not cause a crash:

void MainWindow::trayIconMessageClicked()
{
QMessageBox box(QMessageBox::Information, "MyApp", "The message...", QMessageBox::Ok);
box.setWindowIcon(box.iconPixmap());
box.exec();
show();
hide();
}

The show() and hide() act on the main window.

glafauci
8th August 2012, 13:34
I experimented this behavior today, and I tried it very weird.
I had exactly your conclusions.
Do you find the solution to this problem?

PS The application don't crashes: it close normally, as you give the instruction qApp::quit().
Probably, when you close the QMessageBox's modal-window, it's quit() command isn't destroyed: it arrives to the MainWindow, and forces it to quit. So, it'll be a QtMessageBox bug.

dobedidoo
8th August 2012, 15:42
I found some help via this post:
http://stackoverflow.com/questions/5116459/problem-with-hidden-qmainwindow-application-crashes-after-qmessagebox-is-displa

So, the QApplication::quitOnLastWindowClosed(bool) seems to be the issue (and the solution).