Results 1 to 4 of 4

Thread: Validate Data in QDialog

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2007
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Smile Re: Validate Data in QDialog

    I contacted Trolltech support. In case anyone searches this thread for a similar problem, I thought I'd send the resolution. It is not necessary to create one's own ok/cancel buttons, although that would probably work (I didn't try that). It is also not necessary to enable/disable the ok/cancel buttons, but that is a good idea (I didn't try that either). A simpler solution is to override the done() method and do the validation there. To make the dialog disappear, just call the parent's done() method. To keep the dialog on the screen, simply return. Here's some code...

    Thanks for the ideas,
    Joel

    Qt Code:
    1. void DataSourceDlg::done(int r)
    2. {
    3. if(QDialog::Accepted == r) // ok was pressed
    4. {
    5. if(nodeLineEdit->text().size() > 3) // validate the data somehow
    6. {
    7. QDialog::done(r);
    8. return;
    9. }
    10. else
    11. {
    12. statusBar->setText("Invalid data in text edit...try again...");
    13. return;
    14. }
    15. }
    16. else // cancel, close or exc was pressed
    17. {
    18. QDialog::done(r);
    19. return;
    20. }
    21. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jacek; 24th July 2007 at 01:38. Reason: missing [code] tags

Similar Threads

  1. QSqlQueryModel data update
    By psi in forum Qt Programming
    Replies: 4
    Last Post: 20th July 2012, 03:59
  2. QByteArray with network data
    By merlvingian in forum Qt Programming
    Replies: 1
    Last Post: 1st June 2007, 17:53
  3. speed of setdata - lots of items in treeview
    By Big Duck in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2006, 12:53
  4. How to convert binary data to hexadecimal data
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 8th March 2006, 16:17
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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
  •  
Qt is a trademark of The Qt Company.