Link to home
Start Free TrialLog in
Avatar of Ingo Förster
Ingo Förster

asked on

QT Cancel MdiChild creation

In my app I use an mdiArea as central widget. Inside this I create different Childs.

Like:
    MdiChildDiskInfo *child = new MdiChildDiskInfo(this,strDriveName);
    if(child){
        mdiArea->addSubWindow(child);
        child->showMaximized();
    }

Open in new window


The MdiChildDiskInfo is a
class MdiChildDiskInfo : public MdiChildBase
that is basing on
class MdiChildBase : public QMainWindow

Open in new window


The MdiChildDiskInfo is created with
MdiChildDiskInfo::MdiChildDiskInfo(QWidget* parent, const QString &device)
    :strBurnDrive(device){
      setAttribute(Qt::WA_DeleteOnClose);

      this->close();

}

Open in new window


I tried to stop creating the MdiChildDiskInfo with this->close() while the MdiChildDiskInfo is created. The close event is fired.
But always an empty QSubWindow is created. Means child has always an object.

I expect that the child is null when I add this->close() to the constructor. Special in case of Qt::WA_DeleteOnClose. But child is always an object. It looks that the MdiChildDiskInfo is always create also if I say close it.

Finally I want that
MdiChildDiskInfo *child = new MdiChildDiskInfo(this,strDriveName);
will return null to child.
ASKER CERTIFIED SOLUTION
Avatar of Ingo Förster
Ingo Förster

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ingo Förster
Ingo Förster

ASKER

Sorry, it is not possible to edit the solution text so I make a copy now.

I added a var to the MIDChild class. If an error happens I set this to false and do not add the child to the mdiArea. Lets see if this will cause memleaks. I hope not.

    MdiChildDiskInfo *child = new MdiChildDiskInfo(this,strDriveName);
    //We will create the child and set the errorhandle inside the class.
    //If success, we call addSubWindow, if not we will delete it.
    if(child->thisSuccessfullCreated==true){
        mdiArea->addSubWindow(child);

        if(isCascaded()==false){
            child->showMaximized();
        }else{
            child->showNormal();
        }
    }else{
        child->close();
    }

Open in new window