i have a QDialog, frmLogin, which allows a user to well, login
//frmLogin declaration
//frmLogin constructor
frmLogin
::frmLogin(QWidget *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
}
//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
}
To copy to clipboard, switch view to plain text mode
the dialog is created when the user clicks the login button on its parent component, frmWeapon
//frmWeapon declaration
//frmWeapon constructor
: 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);
}
//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);
}
To copy to clipboard, switch view to plain text mode
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?
Bookmarks