Results 1 to 2 of 2

Thread: submitAll() not work for updating fields

  1. #1
    Join Date
    Sep 2007
    Posts
    31
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Question submitAll() not work for updating fields

    Hello.

    I'm using QSqlTableModel:

    QSqlTableModel* sqltm = new QSqlTableModel;
    sqltm->setTable(table);
    sqltm->setFilter(filter);

    I'm inserting there one row:

    sqltm->insertRow(0);

    And modifying data in this row:

    sqltm->setData(sqltm->index(0,tab_col::Col1),data1);
    sqltm->setData(sqltm->index(0,tab_col::Col2),data2);

    And doing submitAll() request:

    sqltm->submitAll();

    Everything works fine, data inserted to DB.

    Then in same session I'm making another set of

    sqltm->setData(sqltm->index(0,tab_col::Col1),data3);
    sqltm->setData(sqltm->index(0,tab_col::Col2),data4);

    operations.

    And trying sqltm->submitAll() again.

    Nothing happening. Inside submitAll()

    case OnManualSubmit:
    for (QSqlTableModelPrivate::CacheMap::ConstIterator it = d->cache.constBegin();
    it != d->cache.constEnd(); ++it)

    "for" cycle skiped.

    Anyone have any thoughts?

  2. #2
    Join Date
    Sep 2007
    Posts
    31
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Exclamation Re: submitAll() not work for updating fields

    I've discovered that inside calling index() second time:

    sqltm->setData(sqltm->index(0,tab_col::Col1),data3);

    hasIndex() returns "fail" because second time rowCount() inside hasIndex():

    Qt Code:
    1. int QSqlTableModel::rowCount(const QModelIndex &parent) const
    2. {
    3. Q_D(const QSqlTableModel);
    4.  
    5. if (parent.isValid())
    6. return 0;
    7.  
    8. int rc = QSqlQueryModel::rowCount();
    9. if (d->strategy == OnManualSubmit) {
    10. for (QSqlTableModelPrivate::CacheMap::ConstIterator it = d->cache.constBegin();
    11. it != d->cache.constEnd(); ++it) {
    12. if (it.value().op == QSqlTableModelPrivate::Insert)
    13. ++rc;
    14. }
    15. } else if (d->insertIndex >= 0) {
    16. ++rc;
    17. }
    18. return rc;
    19. }
    To copy to clipboard, switch view to plain text mode 

    -

    for (QSqlTableModelPrivate::CacheMap::ConstIterator it = d->cache.constBegin();
    it != d->cache.constEnd(); ++it)

    didn't increment rc.

    So index return correct value just on first call, when there is INSERT row in cache.
    Is that a bug?

Similar Threads

  1. submitAll() -> "no fields to update"
    By JeanC in forum Qt Programming
    Replies: 13
    Last Post: 27th February 2011, 23:57

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.