Qt4 Model submits only once



  • I have 2 lineEdit and when I press Apply seems like it will update my values on db only first time; if I change the values and press Apply again, nothing happens anymore.

    Anyone has any idea what's wrong? Thank you.

    MainWidget::MainWidget(QWidget *parent) :
        QTabWidget(parent),
        ui(new U
    list itemi::MainWidget)
    {
        ui->setupUi(this);
    
       QSqlDatabase db = QSqlDatabase::database();
       model = new QSqlTableModel(0, db);
       model->setTable("global_config");
       model->setEditStrategy(QSqlTableModel::OnManualSubmit);
       model->select();
    
       mapper = new QDataWidgetMapper(this);
       mapper->setModel(model);
       mapper->addMapping(ui->lineEdit_tiempoMuestraTXT, 0);
       mapper->addMapping(ui->lineEdit_tiempoMuestraTXT_2, 1);
       mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
       mapper->toFirst();
    }
    
    void MainWidget::on_apply_clicked()
    {
       mapper->submit();
       if (model->submitAll()) {
           model->database().commit();
       }
    }

  • Lifetime Qt Champion

    Hi,

    You should add a debug statement to see if submitAll failed and why



  • seems like submitAll is working properly. The mapper was not updating. I added mapper->toFirst() after model->submitAll() and now works properly.

    Why it needs toFirst() after each submit?


  • Lifetime Qt Champion

    AFAIK you shouldn't need to do that after a submit. Does it also happen if you don't call model->submitAll() ?



  • yes, same stuff. Mapper returns true only the first time; after that only false

    Seems like mapper->currentIndex() becomes -1 after submit and this causes the problem.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.