Results 1 to 4 of 4

Thread: Database issue with adding record using QSqlRelationalTable and QDataWidgetMapper

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2008
    Posts
    38
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Cool SOLVED DB issue with adding record using QSqlRelationalTable and QDataWidgetMapper

    Ok, figured it out... For anyone else who might be experiencing similar issues the fix that I am using is:
    Qt Code:
    1. void employeeForm::go2First()
    2. {
    3. int row = mapper->currentIndex();
    4. if(! mapper->submit())
    5. {
    6. qDebug()<<"lasterror:"<<tableModel->lastError().text();
    7. tableModel->revertAll();
    8. }
    9. mapper->toFirst();
    10. nav->setCurrentRec(mapper->currentIndex()+1);
    11. nav->setTotalRec(tableModel->rowCount());
    12. }
    13. void employeeForm::go2Prev()
    14. {
    15. int row = mapper->currentIndex();
    16. if(! mapper->submit())
    17. {
    18. qDebug()<<"lasterror:"<<tableModel->lastError().text();
    19. tableModel->revertRow(row);
    20. }
    21. if(row > 0)
    22. row--;
    23. mapper->setCurrentIndex(row);
    24.  
    25. nav->setCurrentRec(mapper->currentIndex()+1);
    26. nav->setTotalRec(tableModel->rowCount());
    27. }
    28. void employeeForm::go2Next()
    29. {
    30. int row = mapper->currentIndex();
    31. if(!mapper->submit())
    32. {
    33. qDebug()<<"lasterror:"<<tableModel->lastError().text();
    34. tableModel->revertRow(row);
    35. row--;
    36. }
    37.  
    38. mapper->setCurrentIndex(row);
    39. mapper->toNext();
    40. nav->setCurrentRec(mapper->currentIndex()+1);
    41. nav->setTotalRec(tableModel->rowCount());
    42. }
    43. void employeeForm::go2Last()
    44. {
    45. int row = mapper->currentIndex();
    46. if(!mapper->submit())
    47. {
    48. qDebug()<<"lasterror:"<<tableModel->lastError().text();
    49. tableModel->revertRow(row);
    50. row--;
    51. }
    52. mapper->setCurrentIndex(row);
    53. mapper->toLast();
    54. nav->setCurrentRec(mapper->currentIndex()+1);
    55. nav->setTotalRec(tableModel->rowCount());
    56. }
    To copy to clipboard, switch view to plain text mode 

    Basically, just check if the submit failed, if it did, revert the row changes and update the index counter to match... Then just handle the mapper and anything else!
    AlphaWolfXV
    Last edited by AlphaWolfXV; 4th August 2010 at 18:52. Reason: SOLVED:

Similar Threads

  1. Replies: 2
    Last Post: 13th April 2010, 16:50
  2. Replies: 3
    Last Post: 26th March 2010, 04:32
  3. QDataWidgetMapper issue
    By vitaly in forum Qt Programming
    Replies: 1
    Last Post: 3rd June 2007, 03:28
  4. rollback issue with database
    By Djony in forum Qt Programming
    Replies: 8
    Last Post: 19th February 2007, 15:58
  5. Database access issue
    By Gayathri in forum Newbie
    Replies: 3
    Last Post: 23rd November 2006, 07:41

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.