Hi to All,
I'm working on a SQLITE database and it returns the following error after submiAll() in void frmUnValore_AME::submit() function when I try to run modelAME->database().commit():

QSqlError(-1, "Unable to commit transaction", "cannot commit transaction -
SQL statements in progress")

it's quite strange cause I use this funtion template to edit other tables in the database (and it works). As anyone help me suggesting why it happens?
Thanks!

Qt Code:
  1. #include "frmUnValore_AME.h"
  2.  
  3. /*----------------------------------------------------------------------------*/
  4.  
  5. frmUnValore_AME::frmUnValore_AME(QSqlTableModel *model, const int &isItNew,
  6. QWidget *parent) : QDialog(parent)
  7. {
  8. ui.setupUi(this);
  9. this->setWindowFlags(Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
  10. this->setAttribute(Qt::WA_DeleteOnClose);
  11.  
  12. modelAME = new QSqlTableModel(this);
  13. modelAME = model;
  14.  
  15. if (modelAME->database().transaction())
  16. {
  17. qDebug() << "frmUnValore_AME TRANSACTION database!";
  18. }
  19. else
  20. {
  21. qDebug() << "frmUnValore_AME TRANSACTION FALSE!";
  22. qDebug() << modelAME->database().lastError();
  23. }
  24.  
  25.  
  26. if (isItNew < 0)
  27. {
  28. id = modelAME->rowCount();
  29. modelAME->insertRow(id);
  30. }
  31. else
  32. {
  33. id = isItNew;
  34. }
  35.  
  36. mapper = new QDataWidgetMapper(this);
  37. mapper->setModel(modelAME);
  38. mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
  39. mapper->addMapping(ui.lnePrimo, 1);
  40. mapper->setCurrentIndex(id);
  41.  
  42. connect(ui.btnAnnulla, SIGNAL(clicked()), this, SLOT(revert()));
  43. connect(ui.btnOk, SIGNAL(clicked()), this, SLOT(submit()));
  44.  
  45. qDebug() << "frmUnValore_AME Loaded!";
  46. }
  47.  
  48. /*----------------------------------------------------------------------------*/
  49.  
  50. void frmUnValore_AME::revert()
  51. {
  52. mapper->revert();
  53. qDebug() << "->frmUnValore_AME (Aggiunta Rifiutata!";
  54. modelAME->revertAll();
  55. modelAME->database().rollback();
  56.  
  57. qDebug() << "frmUnValore_AME closed!";
  58. }
  59.  
  60. /*----------------------------------------------------------------------------*/
  61.  
  62. void frmUnValore_AME::submit()
  63. {
  64. if (mapper->submit())
  65. {
  66. mapper->setCurrentIndex(id);
  67. qDebug() << "frmUnValore_AME Ok submit!";
  68.  
  69. if (modelAME->submitAll())
  70. {
  71. if (modelAME->database().commit())
  72. {
  73. qDebug() << "frmUnValore_AME COMMIT database!";
  74. }
  75. else
  76. {
  77. qDebug() << "frmUnValore_AME COMMIT FALSE!";
  78. qDebug() << modelAME->database().lastError();
  79. }
  80. }
  81. else
  82. {
  83. modelAME->revertAll();
  84. modelAME->database().rollback();
  85. QMessageBox::warning(this, tr("Attenzione!"),
  86. tr("Il database ha riportato un errore: %1")
  87. .arg(modelAME->lastError().text()));
  88. }
  89. }
  90. else
  91. {
  92. qDebug() << "No submit!";
  93. QMessageBox::warning(this, tr("Attenzione!"),
  94. tr("Il database ha riportato un errore: %1")
  95. .arg(modelAME->lastError().text()));
  96. }
  97. }
To copy to clipboard, switch view to plain text mode