You never check the cause of the error when writing to the database fails.
QSqlQuery::lastError() doc says : Returns error information about the last error (if any) that occurred with this query..