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. Reading data after submit returns wrong values
Forum Updated to NodeBB v4.3 + New Features

Reading data after submit returns wrong values

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 346 Views 2 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.
  • M Offline
    M Offline
    Mark81
    wrote on last edited by Mark81
    #1

    This is my actual code:

    void DialogEdit::saveBoard(int *row, int *id)
    {
        *row = _modelBoards->rowCount();
        qDebug() << _modelBoards->insertRow(*row);
        qDebug() << _modelBoards->setData(_modelBoards->index(*row, MODEL_BOARDS_COL_NAME), ui->txtName->text());
        qDebug() << _modelBoards->setData(_modelBoards->index(*row, MODEL_BOARDS_COL_DESC), ui->txtDesc->text());
        qDebug() << _modelBoards->submitAll();
        qDebug() << _modelBoards->select();
    
        *id = _modelBoards->data(_modelBoards->index(*row, MODEL_BOARDS_COL_ID)).toInt();
        Q_ASSUME(*id > 0);
    }
    

    The model is an QSqlTableModel with the edit strategy set to OnManualSubmit.
    Sometimes, it happens that id is read as 0, while in the database has the correct value (id INTEGER PRIMARY KEY).
    All the methods return true - I can see the correct value in the db (using DB Browser for SQLite).

    As far as I understand select() is a syncrhonous function, so when it returns the model should be already update.
    Is there anything other I need to do before read the data?

    Qt 5.12.5 under Win7

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

      Hi,

      Since it's "sometimes", did you determine if that happens when your system is under pressure doing some heavy tasks ?

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

      M 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Since it's "sometimes", did you determine if that happens when your system is under pressure doing some heavy tasks ?

        M Offline
        M Offline
        Mark81
        wrote on last edited by
        #3

        @SGaist Unfortunately I didn't find any criteria. I'm just developing with QtCreator.

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

          Does it also happen if you put the database in memory ?

          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

          • Login

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