Results 1 to 3 of 3

Thread: Is third input to createIndex really a pointer?

  1. #1
    Join Date
    Jun 2014
    Posts
    98
    Thanks
    43
    Thanked 4 Times in 4 Posts
    Platforms
    Windows

    Default Is third input to createIndex really a pointer?

    I am going through various PySide tutorials, now learning tree views, and trying to understand a couple of things. In the Model class, there is a parent method which (if I am not mistaken) takes in the model, and an index, and returns the index of its parent node. The parent() method calls the built-in method createIndex(), which at the documentation usage is described thusly:

    def createIndex(row, column, ptr): Creates a model index for the given row and column with the internal pointer ptr
    While that is from Qt, the description is the same at PySide documentation site too.

    And in the treemodel tutorial example, within the parent() method, it is used as follows (trimming away some inessential details):
    Qt Code:
    1. def parent(self, childIndex):
    2. childNode = childIndex.internalPointer() #internal pointer returns node corresponding to index
    3. parentNode = childNode.parent() #this instance of parent() is defined in the TreeItem class
    4. return self.createIndex(parentNode.row(), 0, parentNode) #second input is 0 by convention for tree parent
    To copy to clipboard, switch view to plain text mode 
    My question is this: while we indeed use the internal pointer to pull the childNode, this is not the third input to createIndex. Rather, the input to createIndex is simply the parent node which we have pulled from the childNode. So it seems I am not feeding it an internalPointer at all, but simply something I have extracted from the internalPointer.

    Why describe the third parameter as a pointer when it seems to just be an object (i.e., an item/node in your tree)? Given that I am working in Python, which does not use pointers, what is the third input (and for that matter what is an internalPointer anyway, in Python?).

    Note crossposted at SO:
    http://stackoverflow.com/questions/2...-use-a-pointer
    Last edited by neuronet; 15th July 2014 at 17:17.

  2. #2
    Join Date
    Oct 2012
    Posts
    132
    Thanks
    10
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Is third input to createIndex really a pointer?

    The internal pointer is used by the model to associate the index with the internal data structure (from the docs).

    It seems like you're doing something like the Simple Tree Model Example: http://qt-project.org/doc/qt-4.8/ite...treemodel.html
    Here the internal pointer points to a TreeItem instance which holds data for the index and also a pointer to the parent of the index (which points to another TreeItem instance of course). This pointer is used as internal pointer when creating the parent index.

    Given that I am working in Python, which does not use pointers
    Correct, in Python you don't use pointers (all values are references). Maybe it would make more sense to talk about "internal objects" here.

  3. The following user says thank you to Infinity for this useful post:

    neuronet (15th July 2014)

  4. #3
    Join Date
    Jun 2014
    Posts
    98
    Thanks
    43
    Thanked 4 Times in 4 Posts
    Platforms
    Windows

    Default Re: Is third input to createIndex really a pointer?

    Maybe this is a case where translation of documentation to Python hasn't been as smooth because we don't use pointers

    (Note I just added to original post: I x-posted this to stack overflow)

Similar Threads

  1. Replies: 20
    Last Post: 1st July 2015, 01:19
  2. Replies: 0
    Last Post: 5th December 2013, 06:46
  3. Replies: 0
    Last Post: 28th December 2012, 06:49
  4. Replies: 3
    Last Post: 21st June 2011, 06:25
  5. Replies: 1
    Last Post: 4th December 2010, 17:20

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.