Results 1 to 7 of 7

Thread: QDialog Cleanup

  1. #1
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default QDialog Cleanup

    I have a modeless QDialog owned by a QGraphicsScene. All works well, but if I close the main application while the dialog is showing, the dialog persists unless I manually close it. I've tried calling close(), accept() and other likely functions from the scene's destructor, to no avail.

    What do I have to do to have this dialog close when the application shuts down?

  2. #2
    Join Date
    Aug 2006
    Posts
    77
    Thanks
    14
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDialog Cleanup

    Make the dialog global to the QGraphicsScene with parent = NULL and delete it in the QGraphicsScenes destructor.

  3. #3
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QDialog Cleanup

    Quote Originally Posted by kemp View Post
    Make the dialog global to the QGraphicsScene with parent = NULL and delete it in the QGraphicsScenes destructor.
    That's where I started, and where I've returned to; no joy, the dialog persists after the application shuts down.

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QDialog Cleanup

    Does the following work?

    Qt Code:
    1. QCloseEvent closeEvent();
    2. QApplication::sendEvent(dialog, &closeEvent);
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QDialog Cleanup

    Quote Originally Posted by tbscope View Post
    Does the following work?

    Qt Code:
    1. QCloseEvent closeEvent();
    2. QApplication::sendEvent(dialog, &closeEvent);
    To copy to clipboard, switch view to plain text mode 
    Nope. Still there.

  6. #6
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QDialog Cleanup

    This means you do not have an event loop. I think, not sure though.

    Edit: or, the dialog doesn't handle the event of course.

    Can you repeat the behaviour in a simple example?
    Last edited by tbscope; 8th September 2010 at 18:09.

  7. #7
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QDialog Cleanup

    I kind of solved this. I left pretty much all my code in place, but I know construct the dialog in the main application and pass a pointer to it through a set routine in my QGraphicsScene. As long as I remember to initialize everything immediately following construction, this works, and the dialog behaves as expected upon program termination - that is, it vanishes.

    It isn't a pretty solution, but it works. There's something odd about QGraphicsView/Scene/Item; I've had strange parenting issues with these classes in the past, and I guess this is just another one.

Similar Threads

  1. Replies: 0
    Last Post: 22nd June 2010, 20:27
  2. closing a Qdialog called from a Qdialog
    By OverTheOCean in forum Qt Programming
    Replies: 3
    Last Post: 28th September 2009, 08:02
  3. How to "lock" a new qdialog in another qdialog
    By donglebob in forum Qt Programming
    Replies: 7
    Last Post: 4th February 2009, 08:37
  4. cleanup handler on application close
    By err23 in forum Qt Programming
    Replies: 3
    Last Post: 16th August 2006, 10:56
  5. How to cleanup timers properly?
    By jpn in forum Qt Programming
    Replies: 7
    Last Post: 6th July 2006, 17:52

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.