Results 1 to 9 of 9

Thread: QModelIndex values unexpectedly alternates

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QModelIndex values unexpectedly alternates

    Quote Originally Posted by d_stranz View Post
    However, QModelIndex is not guaranteed to return the same memory address each time the index is requested for a given row and column.
    I would even say it is bound to return a different object.

    The point is that all of them will point to the same item in the model (which can be seen by comparing the internal pointer values).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  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: QModelIndex values unexpectedly alternates

    Quote Originally Posted by wysota View Post
    I would even say it is bound to return a different object.
    Exactly!
    Even if the model would return the same object every time (which it doesn't), the caller would always get a different one since the API returns a copy, not a reference.

    Cheers,
    _

  3. #3
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QModelIndex values unexpectedly alternates

    @q130s - Sorry, I misunderstood your intent (reading comprehension problem).

    Like d_stranz, I'm not that familar with Python but where in your original code do you deselect the clicked on item? Does the following change work?:
    Qt Code:
    1. if len(indexes) > 0:
    2. print(tabular_format.format(
    3. del_or_sel, index_current, index_current.row(),
    4. index_current.data(Qt.DisplayRole).toString(),
    5. index_parent_sel, index_internalid))
    6. self.selectionModel.select(index_current,QItemSelectionModel.Deselect) # added statement
    7. elif len(deselected.indexes()) > 0:
    8. print(tabular_format.format(
    9. del_or_sel, index_deselected, index_deselected.row(),
    10. index_deselected.data(Qt.DisplayRole).toString(),
    11. index_parent_desel, index_internalid))
    12. #self.selectionModel.select(index_deselected,QItemSelectionModel.Deselect) # not necessary
    To copy to clipboard, switch view to plain text mode 

  4. The following user says thank you to norobro for this useful post:

    q130s (8th March 2013)

  5. #4
    Join Date
    Jan 2013
    Posts
    5
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QModelIndex values unexpectedly alternates

    I haven't noticed that there has been responses (no email update feature?) but thanks for that.

    I think I worked it around by something similar to what norobro suggests...comparing qindex.data. Since this works fine for me I'll keep using it but next time when I implement the similar feature I'll think about storing row & column.

Similar Threads

  1. the program has unexpectedly finished
    By narlapavan in forum Qt Programming
    Replies: 9
    Last Post: 9th July 2012, 09:04
  2. How to convert string hex values to its real binary values?
    By AttilaPethe in forum Qt Programming
    Replies: 1
    Last Post: 20th February 2012, 22:47
  3. Program quits unexpectedly
    By MCFormax in forum Newbie
    Replies: 2
    Last Post: 9th November 2011, 02:31
  4. Program has unexpectedly finished
    By Maluko_Da_Tola in forum Newbie
    Replies: 5
    Last Post: 1st December 2010, 09:54
  5. Replies: 1
    Last Post: 18th November 2009, 18:06

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