Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt4 Model submits only once
Forum Updated to NodeBB v4.3 + New Features

Qt4 Model submits only once

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 768 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gatz
    wrote on last edited by
    #1

    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();
       }
    }
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • G Offline
        G Offline
        gatz
        wrote on last edited by gatz
        #3

        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?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • G Offline
            G Offline
            gatz
            wrote on last edited by gatz
            #5

            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.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved