How to get main window from dialog?
Hanna Larsson last edited by
I have a dialog with a buttonbox, OK and Cancel, and I want the OK-button to change the index of my Stacked Widget that is placed in my main window. How do I get the main window from my dialog?
VRonin last edited by VRonin
The correct way would be to make the dialog emit a signal and let the main window take care of changing the index.
anyway if you passed the mainwindow as parent in the constructor dialog you could get it via
As @VRonin said you can retrieve it from the
QObjectparent property. However for the sake of design, you shouldn't do it in the first place. As he hinted, the
QDialogshould know nothing of the outside world (consequently of the
MainWindow) it should rather "notify" others of things that happened (with signals).
This way you also ensure you can use your dialog with a
QWidgetparent, of with
QLineEditparent etc., which is not true if the dialog knows it's owned by a