Look at QSqlQuery::lastError and QSqlDatabase::lastError.