Results 1 to 4 of 4

Thread: QSortFilterProxyModel & QTreeView

  1. #1
    Join Date
    Jan 2006
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QSortFilterProxyModel & QTreeView (Qt4.1)

    I have a Model that I've built that represents a tree of nodes (parented children which are key/value pairs, the default role returning the key), very similar to the simple example provided. When I connect it to a QTreeView, I can expand the tree, collapse it, select it, edit it... basically anything one would expect.

    If, however, I instance a QSortFilterProxyModel with my model as the source, and pass that instance to the QTreeView, as soon as I try to expand any node, the application blows up with
    Qt Code:
    1. warning: ASSERT failure in QVector<T>::at: "index out of range",
    2. file C:/Qt/4.1.0/include/QtCore/../../src/corelib/tools/qvector.h, line 211
    To copy to clipboard, switch view to plain text mode 

    I've run it though a debugger, but I'm not proficient enough with the internals of Qt to figure out the magic going on inside of the QSortFilterProxyModel. Right now, it should just be acting as a one-to-one map, because I've done nothing more than set my model as the source, and it as the model for the QTreeView.

    What I have seen is that it occurs when the request comes from qitemdelegate.cpp looking for the Qt::SizeHintRole (line 258).

    Any suggestions would be very welcome!

    Thanks!
    Gary
    Last edited by Bear; 27th January 2006 at 19:12. Reason: Adding some debugger related notes

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSortFilterProxyModel & QTreeView

    Could we see the backtrace?

  3. #3
    Join Date
    Jan 2006
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSortFilterProxyModel & QTreeView

    Hi, I've encountered the same error twice. I solved it the first time but not the second .

    For the first error, I used in some loops invalid indexes as ending conditions, but proxy model does not seems to appreciate access to invalid indexes (out of range) whereas in my custom model, out-of-range index requests return invalid indexes. So I rewrite my loops to avoid out-of-range index request.

    For the second error, I've not found any solution yet. It seems that proxy model maintains persistent indexes. Thoses indexes are modified by the QTreeView when expanding. But when the QSortFilterProxyModel tries to access thoses indexes, they seems to be invalid. I don't understand why thoses indexes are invalid, since they are set by the QTreeView.

    Edit:
    I've found a workaround for my case. I disconnect the signal between modelReset() and reset() in my derived class constructor of QSortFilterProxyModel and it seems to work. But I only have to fully expand/collapse the tree, maybe there's more to do in your case.
    Last edited by inz; 31st January 2006 at 14:55.

  4. #4
    Join Date
    Jan 2006
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QSortFilterProxyModel & QTreeView

    Quote Originally Posted by inz
    Hi, I've encountered the same error twice. I solved it the first time but not the second .
    On a whim, I downloaded the 4.1.1 alpha, and sure enough everything works fine. A quick diff between that and 4.1.0 indicated that checks were added to test if the index exists before trying to use it. It appears that this is a known bug, although I couldn't find it in the task tracker.

Similar Threads

  1. QTreeView repaint
    By graeme in forum Qt Programming
    Replies: 17
    Last Post: 13th March 2012, 13:27
  2. Direct root childs inline QTreeView
    By faraslacks in forum Qt Programming
    Replies: 2
    Last Post: 15th January 2009, 07:45
  3. QTreeView help
    By bepaald in forum Qt Programming
    Replies: 1
    Last Post: 15th August 2007, 21:22
  4. background image in QTreeView
    By momesana in forum Qt Programming
    Replies: 2
    Last Post: 11th January 2007, 06:25
  5. paint QTreeView item !!
    By mcenatie in forum Qt Programming
    Replies: 2
    Last Post: 19th March 2006, 14:24

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.