Results 1 to 3 of 3

Thread: closing child dialog closes parent dialog

  1. #1
    Join Date
    Feb 2010
    Posts
    7
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default closing child dialog closes parent dialog

    i have a QDialog, frmLogin, which allows a user to well, login
    Qt Code:
    1. //frmLogin declaration
    2. class frmLogin : public QDialog
    3.  
    4. //frmLogin constructor
    5. frmLogin::frmLogin(QWidget *parent) :
    6. QDialog(parent),
    7. ui(new Ui::frmLogin)
    8. //button clicked slot that closes frmLogin
    9. void frmLogin::on_btn_Close_clicked(){
    10. this->close();
    11. this->changedUser = false;//user not changed
    12. }
    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
    Qt Code:
    1. //frmWeapon declaration
    2. class frmWeapon : public QDialog
    3. //frmWeapon constructor
    4. frmWeapon::frmWeapon(QWidget *parent, QString user, int uID)
    5. : QDialog(parent), ui(new Ui::frmWeapon), curUser(user), userID(uID)
    6.  
    7. //button clicked slot that shows frmLogin
    8. void frmWeapon::on_btn_Login_clicked(){
    9. frmLogin l(this);
    10. //hide frmWeapon object for appearance reasons
    11. this->setVisible(false);
    12. //show frmLogin
    13. l.exec();
    14.  
    15. if(l.userChanged()){//login sucessful user changed
    16. this->userID = l.userID();
    17. this->curUser = l.user();
    18. this->setWindowTitle("Weapon Workbench - "+ curUser );
    19.  
    20. //load new users weapon and projectile data
    21.  
    22. //frist remove all old configs
    23.  
    24. do{//remove old weapons
    25. ui->cbo_Weapon->removeItem(1);
    26. }while(ui->cbo_Weapon->count() != 1);
    27. do{//remove old projectiles
    28. ui->cbo_Proj->removeItem(1);
    29. }while(ui->cbo_Proj->count() != 1);
    30.  
    31. //now add new configs
    32. this->populateWpnConfig();
    33. this->populateProjConfig();
    34.  
    35. }
    36. //reshow frmWeapon
    37. this->setVisible(true);
    38.  
    39. }
    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?
    artificial intelligence is no match for natural stupidity

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,709
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: closing child dialog closes parent dialog

    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 :
    Qt Code:
    1. this->setVisible(false);
    To copy to clipboard, switch view to plain text mode 
    And see if frmWeapon gets closed when you dismiss the login dialog.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Feb 2010
    Posts
    7
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: closing child dialog closes parent dialog

    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
    artificial intelligence is no match for natural stupidity

Similar Threads

  1. Last dialog closes app
    By been_1990 in forum Qt Programming
    Replies: 2
    Last Post: 12th April 2010, 15:17
  2. How to blur parent dialog when child dialog is displayed
    By abhilashajha in forum Qt Programming
    Replies: 4
    Last Post: 10th June 2009, 13:01
  3. Dialog closes on pressing Esc key?
    By vishal.chauhan in forum Qt Programming
    Replies: 6
    Last Post: 3rd July 2008, 08:53
  4. Dialog closes immediately
    By bruccutler in forum Qt Programming
    Replies: 5
    Last Post: 21st February 2007, 23:18
  5. QLineedit::returnPressed() closes dialog?
    By geranol in forum Newbie
    Replies: 2
    Last Post: 6th January 2006, 10:18

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.