Important: Please read the Qt Code of Conduct -

Close / Stop MDIChild in its constructor

  • I want to avoid to see empty data tables in my app. So I want to stop MDIChild creation while it is created.
    As sample:

    MdiChildDiskInfo::MdiChildDiskInfo(QWidget* parent, const QString &device)
    void MdiChildDiskInfo::readDiskInfo()
       int nError = 0;
       if( nError == 1 ) this->parentWidget()->close();

    The problem here is, if I run this code the whole app is closed. Without parentWidget() it leaves empty dialogs. So how can I programmatically stop MDIChild creation?

  • @pixbyte
    What "dialogs", there are no dialogs here? The code should probably be one of

    if( nError == 1 ) this->close();
    if( nError == 1 ) this->hide();

    Maybe it does not like you closing/hiding from the constructor, I don't know. Temporarily try it from elsewhere to test.

    You might also want to read e.g. . I'm not sure if it relates to what you see.

  • Dialog or widgets...I think everyone knows what I mean.

  • Lifetime Qt Champion

    @pixbyte said in Close / Stop MDIChild in its constructor:

    Dialog or widgets...I think everyone knows what I mean.

    Yep, but for dialogs, there are Accept and Reject etc so in some use cases its really not the same :)

    if whole application closes, please try setting
    setQuitOnLastWindowClosed(false); on the application.
    and see if that is what you are experiencing.

    That said, its really not super to try to cancel construction from within the ctor.
    However, it should work. ( i think)

    Is there a reason you cant just do

    bool MdiChildDiskInfo::readDiskInfo() .. <<< let it return a status if empty or not

    MdiChildDiskInfo * di = new MdiChildDiskInfo(..)
    if (! di->readDiskInfo() )
    di->DeleteLater(); // nothing to show get rid of it
    (psudo code)

Log in to reply