Results 1 to 2 of 2

Thread: Expected lifetime of QModelIndex?

  1. #1
    Join Date
    Jul 2007
    Posts
    11
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Expected lifetime of QModelIndex?

    Hello,
    I'm building a custom model for some tree-shaped data, and I'm not sure if I'm doing something bad or not.... When I create a QModelIndex to reference one of my data elements, how long is the QModelIndex supposed to be valid?

    What I mean is: I'm using the internalId() property of the QModelIndex to be able to get back
    at my data, so for example, the 5th object inside the 3rd top-level object would get an internal Id equal to 503 (03 => 3rd toplevel, 5xx -> 5th inside it). Now, if one more object is added inside the 3rd top level object, say at row position 1, then this internalId does not point to the same data anymore. Can I assume that any QModelIndex the model returns is not meant to survive across model data changes? Or must I ensure that my items have unique persistent identifiers and use them in creating the internalId?
    Thanks in advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: Expected lifetime of QModelIndex?

    QModelIndex should be considered volatile - never store it anywhere for later use. You can use QPersistentModelIndex if you really can't live without it.

Similar Threads

  1. Qtopia core 4.2.2 cross compile make error
    By smiyai18 in forum Installation and Deployment
    Replies: 2
    Last Post: 28th August 2007, 17:04
  2. Program crashes (SIGSEGV)
    By Voldemort in forum Qt Programming
    Replies: 47
    Last Post: 21st May 2007, 20:09
  3. Compile Errors
    By luffy27 in forum Qt Programming
    Replies: 3
    Last Post: 4th November 2006, 05:26
  4. Delegates and Table
    By ankurjain in forum Qt Programming
    Replies: 8
    Last Post: 18th May 2006, 19:47

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.