Results 1 to 3 of 3

Thread: closeEvent preventing shutdown

  1. #1
    Join Date
    Apr 2006
    Location
    San Francisco, CA
    Posts
    186
    Thanks
    55
    Thanked 12 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default closeEvent preventing shutdown

    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...

    Qt Code:
    1. mpMessageBox = new QMessageBox(QMessageBox::Question, "Name",
    2. QString(tr("Are you sure you want to exit?")),
    3. QMessageBox::Yes | QMessageBox::No, this);
    4. mpMessageBox->setModal(true);
    5. mpMessageBox->setAttribute(Qt::WA_DeleteOnClose);
    6. mpMessageBox->show();
    7. connect(mpMessageBox, SIGNAL(destroyed()), this, SLOT(dismissMsgBox()));
    To copy to clipboard, switch view to plain text mode 

    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.
    Software Engineer



  2. #2
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: closeEvent preventing shutdown

    I don't know if this will make much difference but have you tried making your connect statement before executing your show command? Since you use show( ) I would think this wouldn't be the problem, but I like to connect all signals and slots before showing a dialog. If this doesn't work, could you show the code inside your dismissMsgBox( ) SLOT?

    I just looked in the Qt docs and the SIGNAL destroyed for a QObject says it passes a QObject* as an argument in the SIGNAL so I am guessing you are not capturing the signal since you are trying to get a signal with no arguments. The code should look like:

    Qt Code:
    1. connect( mpMessageBox, SIGNAL( destroyed( QObject* ) ), this, SLOT( dismissMsgBox( QObject* ) ) );
    To copy to clipboard, switch view to plain text mode 

    Do either of these suggestions work?

  3. #3
    Join Date
    Jan 2006
    Posts
    105
    Thanks
    21
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: closeEvent preventing shutdown

    Why don't you use exec() instead of show()?
    This way you wouldn't need any signals and slots at all.

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.