Results 1 to 10 of 10

Thread: Source code for createIndex() ?

Threaded View

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

    Default Re: Source code for createIndex() ?

    Quote Originally Posted by d_stranz View Post
    The third parameter is also defined as a void * pointer, which in reality means it can contain anything that will fit into the size of a pointer (usually the same size as an unsigned long). In Python, you could possibly use this to store the index into a list of objects, for example. The implementation of PySide might even coerce a Python object reference into a pointer "under the hood" so you may be able to store a Python object reference in it.

    But as anda_skoa says, it is rare that you need to use this third parameter unless you are implementing a tree or a proxy model where it would be difficult to navigate the model otherwise.
    Very useful stuff. I am indeed building a tree model by subclassing QAbstractItemModel. I was looking at the implementation of QAbstractTableModel just to check that I understood what I was doing.

    Indeed, in Python, the third input to createIndex is actually just any old Python object, of any type. Typically we just feed in the data item itself to become referred to by the index (e.g., in simpletreemodel example, we give it a TreeItem type directly as the parameter, no pointers or anything like that, which don't exist in Python).

    I have finally started to sort out these issues in a couple of threads over at stack overflow:
    http://stackoverflow.com/questions/2...qt-model-items
    http://stackoverflow.com/questions/2...ject-in-python

    Though I a admit I am still a bit puzzled by the following:
    Qt Code:
    1. inline QModelIndex(const QModelIndex &other)
    2. : r(other.r), c(other.c), p(other.p), m(other.m) {}
    To copy to clipboard, switch view to plain text mode 
    As I said, I am no c++ coder, so this just seems foreign to me. It seems to be creating a QModelIndex out of these r (row), c (column), p (pointer to the data item), and m (I assume the model that it got the index from). But I don't where where it is creating the .row(), .column(), .getInternalPointer(), .model(), and other methods associated with an index. Where is that behavior defined? I can see how it would be fairly easy to get those methods based on the parameters the function is receiving, but would like to see in the source how it all works...
    Last edited by neuronet; 30th December 2014 at 04:08.

Similar Threads

  1. Source code to *.ui
    By Zergi in forum Qt Tools
    Replies: 3
    Last Post: 28th September 2011, 18:12
  2. no source code
    By banlinhtienphong in forum General Programming
    Replies: 1
    Last Post: 25th July 2011, 17:19
  3. Source code
    By afflictedd2 in forum Qt Programming
    Replies: 3
    Last Post: 4th November 2008, 09:04
  4. source code
    By Colx007 in forum Newbie
    Replies: 5
    Last Post: 19th December 2007, 09:15
  5. Qte source code
    By Gaurav vyas in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 1st July 2007, 14:11

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.