Unsolved closing child object causes parent to be closed
-
@fireyyouth
you should try with
app.setQuitOnLastWindowClosed(false); -
@mrjj but the case here is that the application exits when there are still two windows out there, one of them visible.
-
@fireyyouth
Yes but if only one is considered toplevel ( never tested with only Dialogs) , it would still close.
At least for testing. then we know its not due to the auto close feature.
If it stills quits, its something else.Also you can add a a line after app.exec() and put break point on it.
That way we can see if the exit is due to normal reason or something else.I assume you didn't not hook up anything to the quit() slot or by other means added code to end application ?
-
I updated my question, please take a look
-
@fireyyouth
and did testing with
app.setQuitOnLastWindowClosed(false);
still close the whole app ? -
no the programs hangs
-
@fireyyouth
hangs?
The dialogs stays on screen but can no longer be clicked ?
or how hangs ? -
@mrjj I mean after closing all the dialog i can click on , the QApplication::exec() does not return.
-
@fireyyouth
ahh, that is expected as we disable the auto close.
You must close it yourself using quit() in application.You can use DeleteOnclose on the dialog and call QApplication::quit() in destructor.
Of Course it depends on what design you're after.
So if you do this in Dialog ( the parent), it should do as you want. -
I get what you mean and i think it could work. thanks. but I still want to understand why the original case happened, can you explain?
-
@fireyyouth
I did not test it, but i think that a invisible dialog do not count as "window" and hence
it would auto close when you closed the dialog. ( even if not the last "window" )You can test if the dialog is considered that.
Its normally/used to be a flag. You set. QMianwindow has it.
Not sure with Dialogs in all cases. Where parent is also a Dialog
http://doc.qt.io/qt-5/qt.html#WindowType-enum
Also I could not find the exact doc on the rules for being top level and the auto close feature.
I did find that
"QDialog and QMainWindow widgets are by default windows, even if a parent widget is specified in the constructor. This behavior is specified by the Qt::Window flag."You could try the code, to see what is listed.
void showAllTopLevelWidgets() { foreach (QWidget *widget, QApplication::topLevelWidgets()) { // print out info } }
So overall the dialogs are not having WType_TopLevel if they have parents or something like that.
Where as QMainWindow has it.
You can give flags to Dialog in constructor so I think u can make it work like MW with some research.
I think WType_TopLevel is called something else. But not sure.
My Google fu failed me. Looking in the source code would bring light.