Results 1 to 3 of 3

Thread: QAbstractItemModel with two QSortFilterProxyModels

  1. #1
    Join Date
    May 2013
    Posts
    35
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default QAbstractItemModel with two QSortFilterProxyModels

    Hello,

    I'm trying to access data in a QAbstractItemModel implementation that is fitlered through two successive QSortFitlerProxyModel instances.

    The data is stored with two identifiers "section" and "name". I instance a "section" filter to filter the model items first by their section, then a "name" filter to choose an item by it's particular name.

    The problem is, I can't seem to access the original data through the name filter.

    The data filters fine, and the correct columns are being mapped to the source model, but trying to access the data from the second-level filter results in an invalid index at the source level (row() and column() == -1).

    Qt Code:
    1. void buldAndTestModel (QAbstractItemModel *source, const QString &sectionName, const QString &name)
    2. {
    3. sectionModel->setSourceModel(source);
    4. sectionModel->setFilterRegExp(sectionName);
    5. sectionModel->setFilterKeyColumn(1);
    6.  
    7. nameModel->setSourceModel(sectionModel);
    8. nameModel->setFilterRegExp(name);
    9. nameModel->setFilterKeyColumn(0);
    10.  
    11. QStringList valueList = nameModel->data(nameModel->index(0, 2, QModelIndeX())).toStringList();
    12.  
    13. //valueList is empty and the call to the source->data method reveals index.row() and index.column() == -1
    14. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QAbstractItemModel with two QSortFilterProxyModels

    What about the index returned from nameModel->index(0, 2, QModelIndex())?
    Is nameModel->rowCount() > 0? Is nameModel->columnCount() >= 3?

    Cheers,
    _

  3. #3
    Join Date
    May 2013
    Posts
    35
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QAbstractItemModel with two QSortFilterProxyModels

    Rats. columnCount() was causing the problem. It was reporting 2, changed to 3 and it's good. Thanks.

Similar Threads

  1. QAbstractItemModel on QGraphicsView
    By wagmare in forum Newbie
    Replies: 0
    Last Post: 24th May 2012, 08:06
  2. qAbstractItemView, QAbstractItemModel...
    By jano_alex_es in forum Newbie
    Replies: 2
    Last Post: 18th May 2009, 09:22
  3. Checkboxes in QAbstractITemModel
    By Valheru in forum Qt Programming
    Replies: 5
    Last Post: 28th November 2007, 20:23
  4. Replies: 10
    Last Post: 19th October 2007, 19:17
  5. QAbstractItemModel shifiting up and down
    By mattjgalloway in forum Qt Programming
    Replies: 2
    Last Post: 6th June 2007, 08:41

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
  •  
Qt is a trademark of The Qt Company.