Hello!

I am looking for a good way to validate a form.

The form contains:

- line edits: customer name and address, fetched from a qdialog
- qtableview: invoice positions

The approach I am using so far is to set a private member variable

Qt Code:
  1. int CustomerKey
To copy to clipboard, switch view to plain text mode 

if a customer was chosen from the list and inserted into the form and validate like this:

Qt Code:
  1. if (!CustomerKey)
  2. {
  3. QMessageBox::warning(0, QObject::tr("Problem"),"No customer selected");
  4. return 1;
  5. }
To copy to clipboard, switch view to plain text mode 

To check if invoice positions are present I use the following code:

Qt Code:
  1. QSqlQuery query;
  2.  
  3. query.exec("SELECT count(*) FROM tempinvoiceentries");
  4.  
  5. if (query.next())
  6. {
  7. if (query.record().value(0).toInt() == 0) //improve check !!
  8. {
  9. QMessageBox::warning(0, QObject::tr("Problem"),"No invoice entries");
  10. return 1;
  11. }
  12. else
  13. {
  14. //valid entries present...
  15. return 0;
  16. }
  17. }
To copy to clipboard, switch view to plain text mode 

This methods work so far, but I am not sure if they are sufficient. Do you have ideas how to improve the validation?

Kind regards,
HomeR