Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

CDialog OnInitDialog()



  • I'm porting a lot a MFC code to Qt right now.

    Most of the CDialog derived dialogues don't initialise everything in the ctor. MFC programmers often construct the dialogues, then maybe invoke a few methods to configure this or that and then call (e.g.) DoModal() to display the dialogue. At this point (just before the dialogue is displayed), the OnInitDialog() method is invoked:

    "Override this method if you want to perform special processing when the dialog box is initialized. In the overridden version, first call the base class OnInitDialog but ignore its return value. You will typically return TRUE from your overridden method."

    Is there a method/slot in QDialog that I can override that is called immediately before the dialogue is displayed using e.g. show() or exec()?

    Thanks
    David



  • @Perdrix
    Yes, you need to sub-class and override QWidget::showEvent(), https://doc.qt.io/qt-5/qwidget.html#showEvent, for any widget, including QDialog.


Log in to reply