Results 1 to 3 of 3

Thread: QSqlTableModel and OnManualSubmit appears buggy if rows are removed

  1. #1
    Join Date
    Dec 2009
    Posts
    47
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default QSqlTableModel and OnManualSubmit appears buggy if rows are removed

    Hi

    Related to a topic discussed a few months ago (http://www.qtcentre.org/threads/2393...OnManualSubmit), I find QSqlTableModel behaves unexpected, not to say buggy, if used with OnManualSubmit. This notably affects removed rows.
    Removed rows are highlighted with '!' in views, but are still counted by QSqlTableModel::rowCount(). Here the implementation from qsqltablemodel.cpp
    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 
    Line 12 checks for newly, not yet commited inserts and line 13 increments the row count accordingly. IMO, the same should be done for removed, but not yet commited rows. Somthing like the following statements is missing:
    Qt Code:
    1. if (it.value().op == QSqlTableModelPrivate::Delete)
    2. --rc;
    To copy to clipboard, switch view to plain text mode 
    Similarly, removed rows should no longer be visible in views. This has been reported to the Qt bug tracker as suggestion (http://bugreports.qt.nokia.com/browse/QTBUG-492); why is this not considered a plain and simple bug?

    Does anybody have awrapper that solves these deficiencies of QSqlTableModel?

    Regards

    Al_

  2. #2
    Join Date
    Dec 2009
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSqlTableModel and OnManualSubmit appears buggy if rows are removed

    I just want to say that I too have not been successful when trying to delete selected rows.

  3. #3
    Join Date
    Dec 2009
    Posts
    47
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: QSqlTableModel and OnManualSubmit appears buggy if rows are removed

    Actually, it works to delete rows from code, but the deleted rows still remain visible and the row count of the model does not change. The row is removed from the model only after submitAll() and then the row count is finally also reflecting the correct new count.

    As you are also affected by this behaviour, I suggest you have a look at http://bugreports.qt.nokia.com/browse/QTBUG-492; you have also the option to vote to have this issue resolved.

    If QSqlTableModel::removeRows (or QAbstractItemModel::removeRow) does not work at all for you, then you have a different issue; in that case feel free to post code to scrutinze.

    Cheers

    Al_

Similar Threads

  1. How to restore removed widget from QMdiArea ?
    By remdex in forum Qt Programming
    Replies: 1
    Last Post: 7th August 2009, 20:59
  2. QSqlTableModel inserts empty rows
    By Nesbitt in forum Qt Programming
    Replies: 2
    Last Post: 6th August 2008, 13:47
  3. Replies: 4
    Last Post: 9th May 2008, 18:02
  4. buggy undo example
    By Gopala Krishna in forum Qt Programming
    Replies: 2
    Last Post: 21st August 2007, 20:33
  5. viewing removed but not submitted rows
    By maxel in forum Qt Programming
    Replies: 6
    Last Post: 6th October 2006, 18:20

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.