Or instead if fiddling with the transient QSqlQuery here use the setQuery() overload that takes a query string and database connection.

Cheers,
_