This usually isn’t InnoDB itself, but how Qt’s SQL layer manages connections and transactions. In Qt, transactions are per connection, not per thread or per query, and mixing multiple QSqlDatabase connections in the same GUI thread can easily lead to undefined behavior if objects outlive their connection or if a connection is implicitly reused. A very common pitfall is reusing the default connection name or letting a QSqlQuery exist after its connection was replaced or closed. When that happens, transaction() may silently fail and lastError() stays empty because the driver thinks the connection is valid, but it’s no longer in a clean transactional state.
The fact that START TRANSACTION / COMMIT / ROLLBACK works via exec() strongly points to a Qt MySQL driver issue or misuse, not a MySQL server problem. Make sure every connection has a unique connection name, is opened once, lives as long as its queries, and that no query from another module is accidentally using the same connection while a transaction is active. Also verify autocommit is disabled when you expect transaction() to work, and don’t mix implicit and explicit transactions on the same connection.
If this setup has already caused inconsistent data or partial commits during failed rollbacks, it’s worth validating table integrity. Native tools like CHECK TABLE help, but if corruption or orphaned rows show up, Stellar Repair for MySQL can be useful to recover data from damaged InnoDB tables that Qt/MySQL tooling can’t safely dump.





Reply With Quote
Bookmarks