C++ (Qt)
QModelIndex current = currentIndex();
...
// updating
...
if( current.row() >= model()->rowCount() )
current = model()->index( model()->rowCount() - 1, current.column() );
if( current.column() >= model()->columnCount() )
current = model()->index( current.row(), model()->columnCount() - 1 );
setCurrentIndex( current );