Results 1 to 3 of 3

Thread: How to close a local QDialog?

  1. #1
    Join Date
    Apr 2010
    Posts
    98
    Thanks
    19
    Thanked 8 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Question How to close a local QDialog?

    My application shows an icon in system tray which allows user to quit the application. Sometimes, my app will popup a dialog to let user verify.

    Qt Code:
    1. void MyWidget::showWarning()
    2. {
    3. QDialog dialog;
    4. ...
    5. ...
    6. int result = dialog.exec();
    7. if(result == QDialog::Accepted)
    8. {
    9. ...
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

    The problem is, if the local QDialog object is executing when user quits the app.MyWidget will be deleted before the line
    Qt Code:
    1. if(result == QDialog::Accepted)
    To copy to clipboard, switch view to plain text mode 
    is called, which makes the app crash.

    So, how do I safely finish the QDialog when the user quits the app?
    It's not the goodbye that hurts,but the flashback that follow.

  2. #2
    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: How to close a local QDialog?

    Which version are you using ? I somewhat remember this was a bug in Qt..
    anyway you can try catching QCoreApplication::aboutToQuit and closing the dialog yourself :-)

  3. #3
    Join Date
    Apr 2010
    Posts
    98
    Thanks
    19
    Thanked 8 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to close a local QDialog?

    Quote Originally Posted by aamer4yu View Post
    Which version are you using ? I somewhat remember this was a bug in Qt..
    anyway you can try catching QCoreApplication::aboutToQuit and closing the dialog yourself :-)
    I'm using 4.6. Well, I will try that. Thanks~
    It's not the goodbye that hurts,but the flashback that follow.

Similar Threads

  1. Deleting QDialog object on close
    By ahmdsd_ostora in forum Qt Programming
    Replies: 2
    Last Post: 28th June 2010, 09:55
  2. Disable Close button (X) of a QDialog
    By BrainB0ne in forum Qt Programming
    Replies: 29
    Last Post: 8th December 2009, 17:01
  3. How can I avoid a QDialog close?
    By ricardo in forum Qt Programming
    Replies: 7
    Last Post: 11th May 2009, 19:29
  4. Replies: 1
    Last Post: 7th July 2007, 09:03
  5. showing close Button(x) in QDialog
    By vishal.chauhan in forum Newbie
    Replies: 6
    Last Post: 4th April 2007, 10:01

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.