View Full Version : QDialog Cleanup
SixDegrees
8th September 2010, 14:53
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?
kemp
8th September 2010, 15:03
Make the dialog global to the QGraphicsScene with parent = NULL and delete it in the QGraphicsScenes destructor.
SixDegrees
8th September 2010, 15:29
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.
tbscope
8th September 2010, 16:05
Does the following work?
QCloseEvent closeEvent();
QApplication::sendEvent(dialog, &closeEvent);
SixDegrees
8th September 2010, 17:56
Does the following work?
QCloseEvent closeEvent();
QApplication::sendEvent(dialog, &closeEvent);
Nope. Still there.
tbscope
8th September 2010, 18:02
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?
SixDegrees
8th September 2010, 18:43
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.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.