Results 1 to 3 of 3

Thread: Problem dealing with QDialog

  1. #1
    Join Date
    Jun 2010
    Posts
    137
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Problem dealing with QDialog

    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 

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Problem dealing with QDialog

    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. accept(); // Call accept here
    30. //this->hide();
    31. }
    32. }
    33.  
    34. QStringList formDialog::returnFormdata()
    35. {
    36. return list;
    37. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jun 2010
    Posts
    137
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem dealing with QDialog

    Yes it's working. Thank you tbscope. I understood the problem.

Similar Threads

  1. Replies: 2
    Last Post: 6th July 2010, 02:08
  2. Replies: 5
    Last Post: 25th May 2008, 08:22
  3. Replies: 2
    Last Post: 15th February 2008, 01:21
  4. Dealing with bzip2 compressed tar files
    By momesana in forum Qt Programming
    Replies: 1
    Last Post: 25th September 2007, 11:56
  5. dealing individual objects
    By kingslee in forum General Programming
    Replies: 9
    Last Post: 15th November 2006, 01:28

Tags for this Thread

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.