Results 1 to 6 of 6

Thread: Closing a dialog using a button

  1. #1
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Closing a dialog using a button

    Hi

    I need to close the dialog box using a button. I have 4 line edits and i need to save the values into a variable before closing the dialog.

    I have a mainwindow and a dialog.

    this is my code, to open the dialog b4 the main window.

    Qt Code:
    1. void desktop::newdevice()
    2. {
    3. QDialog dlg;
    4. Ui::newdevice newui;
    5. newui.setupUi(&dlg);
    6.  
    7. identityreaddata();
    8. dlg.setWindowTitle("Title");
    9. newui.statuslabel->setText("Please enter the details");
    10.  
    11. //if(dev_email == '\0' || dev_serialno == '\0'|| dev_devicename == '\0' )
    12. {
    13. if(dlg.exec()== QDialog::Accepted);
    14. {
    15. devicename = newui.devnameEdit->text();
    16. password = newui.passEdit->text();
    17. email = newui.emailEdit->text();
    18. slno = newui.slnoEdit->text();
    19. qDebug () << "device name"<<devicename;
    20. qDebug () << "password"<<password;
    21. qDebug () << "email"<<email;
    22. qDebug () << "slno"<<slno;
    23. connect(newui.updateButton, SIGNAL(clicked()),SLOT (QDialog::close()));
    24.  
    25. }
    To copy to clipboard, switch view to plain text mode 

    but when i press the update button, the dialog doesnt close. I have to press the x button on the right top corner to close it.

    Can somebody help me with this??

  2. #2
    Join Date
    Apr 2008
    Location
    Pittsburgh,PA,USA
    Posts
    48
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Closing a dialog using a button

    Move line 23 to line 6
    John

  3. #3
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: Closing a dialog using a button

    did that. No change. I still have to close it manually with the X button.

  4. #4
    Join Date
    Jul 2006
    Location
    Atlanta, GA
    Posts
    86
    Thanks
    26
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Closing a dialog using a button

    Shouldn't you
    Qt Code:
    1. whatever->setAttribute(Qt::WA_DeleteOnClose)
    2. connect(newui.updateButton, SIGNAL(clicked()), this, SLOT(close()));
    To copy to clipboard, switch view to plain text mode 
    fnmblot
    --------------------------------------
    Gee Ricky, I'm sorry your mom blew up.

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Closing a dialog using a button

    I guess it should be
    Qt Code:
    1. connect(newui.updateButton, SIGNAL(clicked()), &dlg, SLOT(close()));
    To copy to clipboard, switch view to plain text mode 
    after you have setup the gui, but you can do it also inside the Designer...

  6. #6
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: Closing a dialog using a button

    Quote Originally Posted by Lykurg View Post
    I guess it should be
    Qt Code:
    1. connect(newui.updateButton, SIGNAL(clicked()), &dlg, SLOT(close()));
    To copy to clipboard, switch view to plain text mode 
    after you have setup the gui, but you can do it also inside the Designer...
    thanks mate. Ur code works for me!!

Similar Threads

  1. Dialog is not closing
    By manmohan in forum Newbie
    Replies: 5
    Last Post: 1st December 2008, 17:04
  2. Remove close button on a Dialog in Linux
    By Krish_ng in forum Qt Programming
    Replies: 5
    Last Post: 20th July 2007, 07:10
  3. Replies: 2
    Last Post: 5th February 2007, 17:42
  4. closing dialog in hidden main Widget
    By Lele in forum Qt Programming
    Replies: 3
    Last Post: 6th December 2006, 10:35
  5. Replies: 3
    Last Post: 16th November 2006, 12:24

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.