QSqlQuery query; query.prepare("SELECT * FROM employees WHERE age > :age"); query.bindValue(":age", 30); query.exec();
QSqlQuery query; query.prepare("INSERT INTO employees (name, age, salary) VALUES (?, ?, ?)"); query.addBindValue("John"); query.addBindValue(35); query.addBindValue(50000.0); query.exec();In this example, we prepare a SQL statement with positional placeholders, and bind the values to them using addBindValue() method. The query is then executed, and the new record is added to the database. The QSqlQuery class is part of the QtSql package in the Qt library, which provides support for database connectivity and manipulation.