Hi,

I have come across an issue with showing dialog box in my application. The problem is, I have a main application from where a dialog box is showed when a user clicks on a button. And my dialog box comprises of 2 LineEdit widgets and two Button widgets "OK" & "Cancel". I have connected the accept and reject result codes to respective buttons.

During the validation I have to check if the two lineedits are not empty when the user clicks on the "OK" button. If they are empty I have to keep the dialog box active otherwise close it. My problem is the dialog box is closed even if the fields are empty. I am confused on how to make this with my written logic code.

Qt Code:
  1. void MainWindow::getFormdetails()
  2. {
  3. fd = new formDialog();
  4.  
  5. if(fd->exec() == 1)
  6. {
  7. data = fd->returnFormdata();
  8. qDebug() << data;
  9. }
  10. }
  11.  
  12. formDialog::formDIalog()
  13. {
  14. connect(okButton, SIGNAL(clicked()), this, SLOT(formFieldCheck()));
  15. connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
  16. connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
  17. }
  18. void formDialog::formFieldCheck()
  19. {
  20. if(formLedit[0]->text().isEmpty() || formLedit[1]->text().isEmpty())
  21. { QMessageBox::information(this, tr("Empty Field"),
  22. tr("Please enter a name."));
  23.  
  24. }
  25. else {list.append(formLedit[0]->text());
  26. list.append(formLedit[1]->text());
  27. list.append(age->text());
  28. list.append(gender->currentText());
  29. this->hide();}
  30. }
  31.  
  32. QStringList formDialog::returnFormdata()
  33. {
  34. return list;
  35. }
  36.  
  37. I would really appreciate if any one can help me with this.
To copy to clipboard, switch view to plain text mode