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
int CustomerKey
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:
if (!CustomerKey)
{
return 1;
}
if (!CustomerKey)
{
QMessageBox::warning(0, QObject::tr("Problem"),"No customer selected");
return 1;
}
To copy to clipboard, switch view to plain text mode
To check if invoice positions are present I use the following code:
query.exec("SELECT count(*) FROM tempinvoiceentries");
if (query.next())
{
if (query.record().value(0).toInt() == 0) //improve check !!
{
return 1;
}
else
{
//valid entries present...
return 0;
}
}
QSqlQuery query;
query.exec("SELECT count(*) FROM tempinvoiceentries");
if (query.next())
{
if (query.record().value(0).toInt() == 0) //improve check !!
{
QMessageBox::warning(0, QObject::tr("Problem"),"No invoice entries");
return 1;
}
else
{
//valid entries present...
return 0;
}
}
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
Bookmarks