Results 1 to 3 of 3

Thread: QSqlTableModel inserts empty rows

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QSqlTableModel inserts empty rows

    Hi

    I have noticed that QSqlTableModel inserts empty rows after setting setFilter when previous setFilter returned 0 rows. I am using Qt 4.3.4.

    Similar problems ware described in:
    Bug 170783
    Bug 180617
    Bug 194644
    Bug 203724

    I have check the sequence of signals emitted by QSqlTableModel (QAbstractItemModel). My example table (database is SQLite):
    Qt Code:
    1. q.exec(QLatin1String("create table t1(id integer primary key, f1 varchar)"));
    2. q.exec(QLatin1String("insert into t1(f1) values('a')"));
    3. q.exec(QLatin1String("insert into t1(f1) values('a')"));
    4. q.exec(QLatin1String("insert into t1(f1) values('a')"));
    5. q.exec(QLatin1String("insert into t1(f1) values('b')"));
    6. q.exec(QLatin1String("insert into t1(f1) values('b')"));
    To copy to clipboard, switch view to plain text mode 

    Here is the sequence of signals:

    1. setfilter("f1 = 'c'") - model sholud return 0 rows
      1. rowsAboutToBeRemoved
      2. rowsRemoved
      3. modelAboutToBeReset
      4. modelReset

      Now model is empty.
    2. setFilter("f1 = 'a'") - model should return 3 rows
      1. modelAboutToBeReset (why? model was already reset at the end of previous step)
      2. rowsAboutToBeInserted
      3. rowsInserted (everything is ok, i can see 3 rows)
      4. modelReset (here is the problem)

      Now model has 3 empty rows.
    3. setFilter("f1 = 'a'") - same as setp 2
      1. rowsAboutToBeInserted
      2. rowsInserted

      Now model has 6 rows (3 empty and 3 valid).


    It looks like resetting model in step 2 is not necessary. Is there any way to get rid of it? Or to fix the order of signals? modelReset sholud be right after modelAboutToBeReset not after rowsInserted.

    Unfortunately QAbstractItemModel::reset() is not virtual so I cannot reimplement it.

    Thanks.

    PS Example program is in the attachment.
    Attached Files Attached Files

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.