altered:
using QSQLDatabase to avoid setting the lastErrorMessage in the loop