QDialog exec returning Rejected always

540 views Asked by At

I have a QDialog box which accepts password and has a Ok button. When closing the Dialog box on "X", a function should be called. But that function is being called even if clicked on Ok button. Qdialog exec function is always returning Rejected. Code:

if (password->exec() == QDialog::Accepted) {
  QString passwordText = passwordEntry->text();
   }
  else 
  {
  sshDialogBoxClosed();
  }
  delete password;

In any case sshDialogBoxClosed() function is being called. Please help me to resolve this issue. Thanks in Advance

1

There are 1 answers

0
MaxVerro On

You need to connect the "Ok" button with the "accept" slot and the "Cancel" button with the "reject" slot.

QDialog::connect(AcceptButton,SIGNAL(clicked(bool)),this,SLOT(accept()));
QDialog::connect(RejectButton,SIGNAL(clicked(bool)),this,SLOT(reject()));