This is how I get the last entry.

Qt Code:
  1. QSqlQuery query("SELECT uid from main");
  2. query.last();
To copy to clipboard, switch view to plain text mode 
Then I set that to be the max of my uidSpinbox
Qt Code:
  1. fvui.uidSpinBox->setMaximum(query.value(0).toInt());
To copy to clipboard, switch view to plain text mode