Results 1 to 15 of 15

Thread: MainWindow disappearing when loading a QMessageBox

  1. #1
    Join Date
    Jun 2007
    Location
    Plymouth, UK
    Posts
    36
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default MainWindow disappearing when loading a QMessageBox

    Dear all,

    I'm experiencing a strange issue, never happened to me before.

    In a class of my application I've created a simple SIGNAL-SLOT mechanism to manage the pressing of the "Exit" button by the user:

    Qt Code:
    1. // Exit buttons
    2. QObject::connect(mainWindow->pushButton_Exit, SIGNAL(released()), this, SLOT(exitApplication()));
    3. QObject::connect(this, SIGNAL(confirmClosing()), qApp, SLOT(quit()));
    To copy to clipboard, switch view to plain text mode 

    mainWindow is obviously the main window of my application, defined as a member of a class created through the designer (and then made child of QMainWindow).

    The exitApplication() slot provides to prompt the user with a QMessageBox, asking him to confirm the exiting:

    Qt Code:
    1. // Show a dialog box asking confirmation to the user
    2. int reply;
    3. reply = QMessageBox::warning(this, tr("Application exit"),
    4. tr("An evolution is in progress.\nAre you really sure you want to exit now?"),
    5. QMessageBox::No | QMessageBox::Default, QMessageBox::Yes |
    6. QMessageBox::Escape);
    To copy to clipboard, switch view to plain text mode 

    (the code continue with something like: if yes then ::exit(0))

    The problem is that, when this QMessageBox appears, the application's main window disappears. Even if I press "No" on the dialog, the main window doesn't re-appears. The application still runs.

    Any clue about the reason of this behaviour?

    Many thanks,
    Fabio

  2. #2
    Join Date
    Jan 2008
    Location
    Brasil
    Posts
    131
    Thanks
    18
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Lightbulb Re: MainWindow disappearing when loading a QMessageBox

    Please, see Event Close Window. The example is found in MainWindow examples and demos.

    Marcelo Geyer
    Brazil.

  3. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MainWindow disappearing when loading a QMessageBox

    Can u show the code of the exitApplication slot ?

  4. #4
    Join Date
    Jun 2007
    Location
    Plymouth, UK
    Posts
    36
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: MainWindow disappearing when loading a QMessageBox

    Quote Originally Posted by estanisgeyer View Post
    Please, see Event Close Window. The example is found in MainWindow examples and demos.

    Marcelo Geyer
    Brazil.
    Thanks for the link Marcelo, but if possible I would like to use my mechanism, which had already provided to be working in a different application.

    Cheers,
    Fabio

  5. #5
    Join Date
    Jun 2007
    Location
    Plymouth, UK
    Posts
    36
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: MainWindow disappearing when loading a QMessageBox

    Quote Originally Posted by aamer4yu View Post
    Can u show the code of the exitApplication slot ?
    Here it is:

    Qt Code:
    1. // Exit application SLOT
    2. void Simulator::exitApplication() {
    3.  
    4. // Check if an evolution or a test are in progress
    5. if ((evolutionInProgress) || (testInProgress)) {
    6.  
    7. // Pause the simulation
    8. mainWindow->checkBox_PauseEvolution->setChecked(true);
    9.  
    10. // Show a dialog box asking confirmation to the user
    11. int reply;
    12. if (evolutionInProgress) reply = QMessageBox::warning(this, tr("Application exit"),
    13. tr("An evolution is in progress.\nAre you really sure you want to exit now?"),
    14. QMessageBox::No | QMessageBox::Default, QMessageBox::Yes | QMessageBox::Escape);
    15. else reply = QMessageBox::warning(this, tr("Application exit"),
    16. tr("A test is in progress.\nAre you really sure you want to exit now?"),
    17. QMessageBox::No | QMessageBox::Default, QMessageBox::Yes | QMessageBox::Escape);
    18.  
    19. // Check the answer provided by the user (exit or not)
    20. if (reply == QMessageBox::Yes) {
    21.  
    22. // If an evolution is running, ask to the user if he'd like to save the population
    23. if ((currentGeneration != 0) && (evolutionInProgress)) {
    24. int answer = QMessageBox::question(this,
    25. tr("Save current population"), tr("Do you want to save the current population, in order to restore the simulation later?"),
    26. QMessageBox::Yes | QMessageBox::Default, QMessageBox::No | QMessageBox::Escape);
    27. if (answer == QMessageBox::Yes) {
    28. savePopulation();
    29. QString directoryName;
    30. directoryName = seedDirectory + "/Gen_" + QString::number(currentGeneration);
    31. QMessageBox::information(this,
    32. tr("Population saved"), tr("The population has been saved into the directory:\n%1").arg(directoryName));
    33. }
    34. }
    35.  
    36. // Quit the application
    37. ::exit(0);
    38.  
    39. } else {
    40.  
    41. // Return to the simulation
    42. mainWindow->checkBox_PauseEvolution->setChecked(false);
    43.  
    44. }
    45.  
    46. } else { // If no simulations or tests are in progress, directly quit the application
    47.  
    48. emit confirmClosing();
    49.  
    50. }
    51.  
    52. }
    To copy to clipboard, switch view to plain text mode 

    Many thanks for your help. It's really appreciated!

    Cheers,
    Fabio

    PS: sorry but I had few very long lines that I had to copy here inserting few returns.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MainWindow disappearing when loading a QMessageBox

    Quote Originally Posted by fabietto View Post
    The problem is that, when this QMessageBox appears, the application's main window disappears. Even if I press "No" on the dialog, the main window doesn't re-appears.
    What happens when you comment out all of the code in Simulator::exitApplication() and click the exit button?

  7. #7
    Join Date
    Jun 2007
    Location
    Plymouth, UK
    Posts
    36
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: MainWindow disappearing when loading a QMessageBox

    Quote Originally Posted by jacek View Post
    What happens when you comment out all of the code in Simulator::exitApplication() and click the exit button?
    The application quits!

  8. #8
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MainWindow disappearing when loading a QMessageBox

    Yes, probably an access violation.
    Do you get any runtime debug warning messages from connect?
    Try running the debug version from a console.

  9. #9
    Join Date
    Jun 2007
    Location
    Plymouth, UK
    Posts
    36
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: MainWindow disappearing when loading a QMessageBox

    Quote Originally Posted by marcel View Post
    Yes, probably an access violation.
    Do you get any runtime debug warning messages from connect?
    Try running the debug version from a console.
    No, no... it quits correctly!

    Maybe that since I first created the main window through the designer the exit button I'm using has got some particular characteristics?

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MainWindow disappearing when loading a QMessageBox

    Quote Originally Posted by fabietto View Post
    the exit button I'm using has got some particular characteristics?
    Yes, it might be connected to some slot that closes the window.

  11. #11
    Join Date
    Jun 2007
    Location
    Plymouth, UK
    Posts
    36
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: MainWindow disappearing when loading a QMessageBox

    Quote Originally Posted by jacek View Post
    Yes, it might be connected to some slot that closes the window.
    It is! I was missing a line in the .h file generated via Qt Designer/UIC, which was implementing exactly what you said. I removed that line and now everything works smoothly. and as expected.

    Thank you very much to all of you!

    Cheers,
    Fabio

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MainWindow disappearing when loading a QMessageBox

    Quote Originally Posted by fabietto View Post
    It is! I was missing a line in the .h file generated via Qt Designer/UIC, which was implementing exactly what you said. I removed that line and now everything works smoothly. and as expected.
    Don't remove any lines from autogenerated code or the problem will come back. Better fix the .ui file.

  13. #13
    Join Date
    Jun 2007
    Location
    Plymouth, UK
    Posts
    36
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: MainWindow disappearing when loading a QMessageBox

    Quote Originally Posted by jacek View Post
    Don't remove any lines from autogenerated code or the problem will come back. Better fix the .ui file.
    Sure, Jacek. I've used the Qt Designer only at the beginning in order to create the skeleton of the main windows. Now I don't generate the .h file automatically, but I simply use a progressively modified version of it.

    Cheers,
    Fabio

  14. #14
    Join Date
    Aug 2006
    Posts
    250
    Thanks
    19
    Thanked 49 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: MainWindow disappearing when loading a QMessageBox

    That's an interesting way to use Designer..

  15. #15
    Join Date
    Jun 2007
    Location
    Plymouth, UK
    Posts
    36
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: MainWindow disappearing when loading a QMessageBox

    Quote Originally Posted by pherthyl View Post
    That's an interesting way to use Designer..
    Probably not the most intelligent, I know... but it's so handy...

Similar Threads

  1. mainwindow disappearing
    By locus in forum Qt Programming
    Replies: 1
    Last Post: 28th January 2007, 09:24

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.