PDA

View Full Version : closing child dialog closes parent dialog



sparticus_37
28th May 2010, 07:22
i have a QDialog, frmLogin, which allows a user to well, login


//frmLogin declaration
class frmLogin : public QDialog

//frmLogin constructor
frmLogin::frmLogin(QWidget *parent) :
QDialog(parent),
ui(new Ui::frmLogin)
//button clicked slot that closes frmLogin
void frmLogin::on_btn_Close_clicked(){
this->close();
this->changedUser = false;//user not changed
}

the dialog is created when the user clicks the login button on its parent component, frmWeapon


//frmWeapon declaration
class frmWeapon : public QDialog
//frmWeapon constructor
frmWeapon::frmWeapon(QWidget *parent, QString user, int uID)
: QDialog(parent), ui(new Ui::frmWeapon), curUser(user), userID(uID)

//button clicked slot that shows frmLogin
void frmWeapon::on_btn_Login_clicked(){
frmLogin l(this);
//hide frmWeapon object for appearance reasons
this->setVisible(false);
//show frmLogin
l.exec();

if(l.userChanged()){//login sucessful user changed
this->userID = l.userID();
this->curUser = l.user();
this->setWindowTitle("Weapon Workbench - "+ curUser );

//load new users weapon and projectile data

//frist remove all old configs

do{//remove old weapons
ui->cbo_Weapon->removeItem(1);
}while(ui->cbo_Weapon->count() != 1);
do{//remove old projectiles
ui->cbo_Proj->removeItem(1);
}while(ui->cbo_Proj->count() != 1);

//now add new configs
this->populateWpnConfig();
this->populateProjConfig();

}
//reshow frmWeapon
this->setVisible(true);

}

currently when i click on the close button for frmLogin it closes its parent frmWeapon, and returns control to frmWeapon s parent which is frmHangar,closing frmWeapon which i dont want to happne, frmHangar is also a QDialog and it is created by my main fucntion. any thoughts?

also in an unreleated question, i was looking at the code for the above dialogs which was generated by QDesigner, and i noticed in the setupUi() function, all the widgets for the form were created with "new", but i found no corresponding "delete", so should i add the "delete" for each componet to prevent memory leaks or should i just leave it as is?

high_flyer
28th May 2010, 11:28
currently when i click on the close button for frmLogin it closes its parent frmWeapon
I don't see anything in the code you posted that should make it behave like that.
My guess is that the weapon dialog is not closed, just hiden.
Comment out :

this->setVisible(false);
And see if frmWeapon gets closed when you dismiss the login dialog.

sparticus_37
28th May 2010, 19:46
thanks that fixed it.

EDIT: ok now i see why that happened, since the parent of frmLogin wasnt visible QT automatically closed all hidden windows that it relied on , returning to frmHangar, the main widget of the program