QSqlQuery query; query.prepare("SELECT * FROM users WHERE age > ?"); query.addBindValue(18); query.executedQuery(); while (query.next()) { // Process each row of results }
QSqlQuery query; query.prepare("UPDATE users SET age = ? WHERE id = ?"); query.addBindValue(25); query.addBindValue(1); query.executedQuery(); if (query.numRowsAffected() > 0) { // Successful update }This example demonstrates how to execute an UPDATE query to modify the value in the "age" column of the "users" table, where the "id" column matches the value 1. The method executedQuery returns the result of the query, and the numRowsAffected method is used to check if any rows were modified. Package library: Qt SQL module.