Results 1 to 9 of 9

Thread: How to validate a form?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2010
    Posts
    91
    Thanks
    38

    Default Re: How to validate a form?

    Thanks for your comment. I have not posted all code because the other checks that are performed are similar to the two types that I mentioned above.

    Some more information:
    The form consists of
    - editable QLineEdits (easy to verify)
    - a QTableView containing a QStandardItemModel called "tempinvoiceentries" (see code)
    - some non-editable QLineEdits that are filled with customer data after a customer is selected from a popup with a QTableView containing a QSqlTableModel with the customer data (after the call the variable CustomerKey is set, see code)

    I would change your return value too, returning 0 (FALSE) for OK seems a little strange.
    I am confused...I thought all applications return 0 on success, why should this be different while using functions?

    Thanks for the hint to use

    Qt Code:
    1. CREATE PROCEDURE isInvoiceEntriesPresent
    To copy to clipboard, switch view to plain text mode 

    This is indeed a good possibility to improve the code and will make things easier, I was not aware of this. Also thanks for the hint to create an enum, so much to learn

    What exactly is the difference between COUNT(*) and COUNT(1) ?

    I read the sqlite docs on this
    count(X)
    The count(X) function returns a count of the number of times that X is not NULL in a group.
    but I don't unterstand what this exactly means.

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to validate a form?

    Applications return an error code in which 0 is 'The operation completed successfully' and other values are pre-defined error codes. If your function only returns SUCCESS or FAILURE (like the code snippet), then the closest match to these would be TRUE and FALSE. You could typedef these values as follows:

    Qt Code:
    1. typedef enum {FAILURE = 0, SUCCESS = !FAILURE} ErrorStatus;
    To copy to clipboard, switch view to plain text mode 

    COUNT(*) will retrieve all rows matching your condition (in your case, all rows, as you have no limits placed, so it will become slower over time and not scale well). It will then validate that the rows actually contain data. I'm sure when you created your schema that some fields you used the "NOT NULL" restriction to ensure they had data.

    COUNT(1) doesn't care if the rows contain data or not, only that they exist.

    Since your code only requires that at least one row exists, you could take it further:

    Qt Code:
    1. SELECT COUNT(1) FROM tempinvoiceentries LIMIT 1
    To copy to clipboard, switch view to plain text mode 

    This will always take the same amount of time to execute regardless of how many entries are in your table.

  3. The following user says thank you to squidge for this useful post:

    homerun4711 (28th February 2011)

  4. #3
    Join Date
    Oct 2010
    Posts
    91
    Thanks
    38

    Default Re: How to validate a form?

    Thanks for the good information, I will rewrite some stuff now. I have a feeling that CREATE PROCEDURE will become a good friend of mine

Similar Threads

  1. How to validate QSQLITE file?
    By rakkar in forum Newbie
    Replies: 1
    Last Post: 24th September 2009, 01:05
  2. Validate a value of lineEdit
    By edgar in forum Qt Programming
    Replies: 1
    Last Post: 6th September 2009, 18:22
  3. How to validate XML against DTD?
    By emental86 in forum Qt Programming
    Replies: 2
    Last Post: 29th April 2009, 13:11
  4. validate database connection
    By hoshy in forum Qt Programming
    Replies: 2
    Last Post: 9th April 2009, 13:14
  5. Validate Data in QDialog
    By jcraig in forum Qt Programming
    Replies: 3
    Last Post: 23rd July 2007, 15:49

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.