QSqlQuery query; query.prepare("INSERT INTO mytable (name, age) VALUES (:name, :age)"); query.bindValue(":name", "John"); query.bindValue(":age", 30); query.exec(); int lastID = query.lastInsertId().toInt();
QSqlQuery query; query.prepare("INSERT INTO mytable (name, age) VALUES (:name, :age)"); query.addBindValue("John"); query.addBindValue(30); query.execBatch(); int lastID = query.lastInsertId().toInt();In this example, we are inserting rows into the 'mytable' table using batch insert and using lastInsertId to retrieve the ID of the last inserted row. Package/library: QtSQL