Results 1 to 2 of 2

Thread: Invalid QItemSelection from QItemSelectionModel

  1. #1
    Join Date
    Jun 2006
    Location
    Sweden
    Posts
    99
    Thanks
    11
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Invalid QItemSelection from QItemSelectionModel

    I have a custom table where items are placed; one per row with a number of columns dedicated to item properties. My table supports extended selection. The items in my table are sorted according to a convoluted scheme. The item order may be changed dramatically at any time (trust me, it's not as weird as it sounds) based on external events.

    It is important for me to retain the selection such that items selected prior to resorting will still be selected afterwards, regardless of their new position in the table. Therefore my data model emits signals before and after a call to the sorting method. The table view saves and resets the item selection in response to the model's signals.

    When an item in a selection is removed from the table, the remaining items should still be selected. Deletion is implemented as removal from the table model's data followed by a call to removeRow. If the item removed is the first in the table (row 0), the selected and deselected QItemSelections in my receiving class both contain several invalid selections {tons of (row,column)==(-1,-1) with isValid()==false}. This only happens when more than one item is selected and row 0 is removed.

    Example: the items from row 0 and 1 are selected and row 0 is deleted.
    selected: (-1,-1) (-1,-1) ... (-1,-1) // n-times where n == number of columns.
    deselected: (-1,-1) (-1,-1) ... (-1,-1) /* same as selected */ (0,0) (0,1) (0,2) ... (0,n)

    Why am i getting the invalid selection? If i change the selection manually after the programmatic reselection i don't get this problem. I could work around the fact that a selection is invalid but i would like to understand the root of the problem.

    Thanks in advance!

  2. #2
    Join Date
    Jun 2006
    Location
    Sweden
    Posts
    99
    Thanks
    11
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Invalid QItemSelection from QItemSelectionModel

    Quote Originally Posted by TheRonin View Post
    Why am i getting the invalid selection?
    Could the problem be caused by deleting the data from the model before doing removeRow?

    I changed the item deletion implementation to do removeRow before removing the data and my program no longer crashes. However, I'm not sure if i've cured the disease or just made a symptom dissapear. Thoughts? Comments?

Similar Threads

  1. Replies: 2
    Last Post: 18th November 2009, 23:14
  2. QItemSelectionModel::selectedIndexes() fail
    By Stapl in forum Qt Programming
    Replies: 1
    Last Post: 22nd October 2009, 01:54
  3. QItemSelectionModel::currentChanged and revert change
    By Lykurg in forum Qt Programming
    Replies: 5
    Last Post: 25th March 2009, 07:48
  4. Invalid plugin
    By reimer in forum Qt Tools
    Replies: 0
    Last Post: 23rd June 2008, 10:43
  5. Selections in a TableView with a QItemSelectionModel
    By xelag in forum Qt Programming
    Replies: 3
    Last Post: 27th November 2006, 09:45

Tags for this Thread

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.