I have attached a pic to illustrate my problems. I would love to manage some behind the scene activities when the user selects an option on the last row (actually its a new blank row inserted whenever the "Number" field of the previous row is updated with a number. It is inserted by a trigger on my Sqlite db) . The delete Column is the last column..its intended to delete the line when the user clicks on the IndexWidget, however, in some instances, the deletion is carried out on the wrong row I would like help here too.

I have written a function for this as shown below has worked once and never again:

Qt Code:
  1. void clsList::addSbj()
  2. {
  3. if (sbjmodel->isDirty()){
  4. int clInd = sbjmodel->fieldIndex("csNo");
  5. int sbjInd = sbjmodel->fieldIndex("subj");
  6. int clNo = 0;
  7. QSqlQuery qry;
  8. qry.exec("SELECT MAX(csNo)FROM setCls_Sbj");
  9. while (qry.next())clNo = qry.value(0).toInt()+1;
  10. int nwrow = ui->sbjV->currentIndex().row();
  11.  
  12. if (nwrow == sbjProxy->rowCount()-1)
  13. {
  14. QString sb(sbjProxy->index(nwrow,sbjInd).data().toString());
  15. if (sb == "<SELECT>")return;
  16. QModelIndex index = sbjProxy->index(nwrow,clInd);
  17. sbjProxy->setData(index,clNo);
  18. qDebug()<<clNo;
  19. sbjmodel->submitAll();
  20. sbjmodel->select();
  21. }
  22. }
  23. }
To copy to clipboard, switch view to plain text mode 

This is not working out! Thank you!

clsSbj.png.