PDA

View Full Version : Closing a dialog using a button



srohit24
20th July 2009, 20:45
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.


void desktop::newdevice()
{
QDialog dlg;
Ui::newdevice newui;
newui.setupUi(&dlg);

identityreaddata();
dlg.setWindowTitle("Title");
newui.statuslabel->setText("Please enter the details");

//if(dev_email == '\0' || dev_serialno == '\0'|| dev_devicename == '\0' )
{
if(dlg.exec()== QDialog::Accepted);
{
devicename = newui.devnameEdit->text();
password = newui.passEdit->text();
email = newui.emailEdit->text();
slno = newui.slnoEdit->text();
qDebug () << "device name"<<devicename;
qDebug () << "password"<<password;
qDebug () << "email"<<email;
qDebug () << "slno"<<slno;
connect(newui.updateButton, SIGNAL(clicked()),SLOT (QDialog::close()));

}

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??

drescherjm
20th July 2009, 20:58
Move line 23 to line 6

srohit24
20th July 2009, 21:14
did that. No change. I still have to close it manually with the X button.

fnmblot
20th July 2009, 21:37
Shouldn't you


whatever->setAttribute(Qt::WA_DeleteOnClose)
connect(newui.updateButton, SIGNAL(clicked()), this, SLOT(close()));

Lykurg
20th July 2009, 22:05
I guess it should be

connect(newui.updateButton, SIGNAL(clicked()), &dlg, SLOT(close()));
after you have setup the gui, but you can do it also inside the Designer...

srohit24
21st July 2009, 05:57
I guess it should be

connect(newui.updateButton, SIGNAL(clicked()), &dlg, SLOT(close()));
after you have setup the gui, but you can do it also inside the Designer...

thanks mate. Ur code works for me!!