Results 1 to 8 of 8

Thread: SqlTableModel not updating AbstractProxyModel

  1. #1
    Join Date
    Feb 2007
    Location
    Italy
    Posts
    69
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default SqlTableModel not updating AbstractProxyModel

    Hello!
    In my application (qt 4.4.2) I've a QSqlTableModel, which is used as source model for a custom proxy model, which does a little more than filtering (so I can't use filter proxy model).

    The table model is source model for a table view while the proxy model is source for a list view.

    But, if I add new record to the sqltablemodel, the list view isn't updated and I don't see anything added.
    I tried overwriting setSourceModel in my proxy, connecting source's dataChanged(...) signal to a new signal which print a message with qDebug, but this message is never printed, so it seems that dataChanged is never called from a QSqlTableModel.

    Is this normal? How can I overcome this updating issue?
    Thanks

  2. #2
    Join Date
    Feb 2008
    Posts
    98
    Thanks
    2
    Thanked 24 Times in 24 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: SqlTableModel not updating AbstractProxyModel

    You need either to call QSortFilterProxyModel::invalidateFilter() whenever your model changes or to set the dynamicSortFilter property to true (warning: slow).

  3. #3
    Join Date
    Feb 2007
    Location
    Italy
    Posts
    69
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: SqlTableModel not updating AbstractProxyModel

    But i'm not using QSortFilterProxyModel! I'm using QAbstractProxyModel... Shall I use SortFilter instead?
    It's quite nonsense, since I don't need any of the features it provides (sort and filtering).

  4. #4
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: SqlTableModel not updating AbstractProxyModel

    Well, if you do not use those features, they hopefully won't use too much processing power ;-)

    The source model does not have to emit dataChanged() if only a new row has been added. That is what rowsInserted() is for.

  5. The following user says thank you to caduel for this useful post:

    akiross (13th November 2008)

  6. #5
    Join Date
    Feb 2007
    Location
    Italy
    Posts
    69
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: SqlTableModel not updating AbstractProxyModel

    Oops! You're so right! I forgot about rowsInserted.
    Anyway that was just a test, the problem remains: view isn't updated correctly (both on row insertion and data changing)...

    The signals and slots used by the model/view framework ensure that each view is updated appropriately no matter how many proxy models are placed between itself and the source model.
    Am I supposed to forward the signals when using abstract proxy models?

  7. #6
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: SqlTableModel not updating AbstractProxyModel

    Your proxy has to tell the view all the view needs to know.
    So, unless your proxy does not show a row that has been modified or inserted, yes, you will need to forward those signals.

  8. #7
    Join Date
    Feb 2007
    Location
    Italy
    Posts
    69
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: SqlTableModel not updating AbstractProxyModel

    Ok, thank you

  9. #8
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: SqlTableModel not updating AbstractProxyModel

    note: you need not only forward the signals, but -depending on what your proxy does- adapt the arguments: maybe you need to adjust the row of a QModelIndex, maybe you need to replace indexes of the source model for ones of your model...)

    Let the source of QSortFilterProxyModel inspire you...

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.