Results 1 to 3 of 3

Thread: Application crasches due to QMessageBox if hidden

  1. #1
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    34
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Question Application crasches due to QMessageBox if hidden

    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:
    Qt Code:
    1. void MainWindow::trayIconMessageClicked()
    2. {
    3. QMessageBox box(QMessageBox::Information, "MyApp", "The message...", QMessageBox::Ok);
    4. box.setWindowIcon(box.iconPixmap());
    5. box.exec();
    6. }
    To copy to clipboard, switch view to plain text mode 
    while the following apparently does not cause a crash:
    Qt Code:
    1. void MainWindow::trayIconMessageClicked()
    2. {
    3. QMessageBox box(QMessageBox::Information, "MyApp", "The message...", QMessageBox::Ok);
    4. box.setWindowIcon(box.iconPixmap());
    5. box.exec();
    6. show();
    7. hide();
    8. }
    To copy to clipboard, switch view to plain text mode 

    The show() and hide() act on the main window.
    Last edited by dobedidoo; 9th December 2009 at 14:01.

  2. #2
    Join Date
    Nov 2010
    Location
    Caccamo (PA), Italy
    Posts
    13
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Application crasches due to QMessageBox if hidden

    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.
    Last edited by glafauci; 8th August 2012 at 13:39.

  3. #3
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    34
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Application crasches due to QMessageBox if hidden

    I found some help via this post:
    http://stackoverflow.com/questions/5...ebox-is-displa

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

Similar Threads

  1. QMessageBox closes entire application
    By Leoha_Zveri in forum Qt Programming
    Replies: 2
    Last Post: 19th September 2009, 11:44
  2. Deploying Qt 4.5.1 Application on RHEL 5.. Pls Help
    By swamyonline in forum Installation and Deployment
    Replies: 0
    Last Post: 28th June 2009, 11:43
  3. About QMessageBox close my tray application
    By Doles in forum Qt Programming
    Replies: 2
    Last Post: 19th July 2008, 21:27
  4. dll + application
    By fpujol in forum Qt Programming
    Replies: 11
    Last Post: 15th April 2007, 18:37

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.