This example may help

Qt Code:
  1. QSqlQuery query;
  2. query.exec("SELECT MAX(id) FROM mytable");
  3. if (query.next()) {
  4. myStringResult = query.value(0).toString();
  5. }
  6. query.finish();
To copy to clipboard, switch view to plain text mode 

off course you need to replace the SQL code inside the .exec(_)