[PyQt] Using QModelIndex.internalPointer

Bakuriu giacomo.alzetta at gmail.com
Sat Dec 5 19:05:48 GMT 2009

David Boddie wrote:
> Then this would indicate that there may be a bug with the createIndex()
> wrapper in PyQt, though it would be difficult to know exactly what the
> cause is without a test case or minimal example that demonstrates the
> problem.
> Which versions of SIP and PyQt are you using?

I'm using PyQt 4.6 and sip 4.9.1-snapshot-20091015
I think it's strange for PyQt to have a bug in such a crucial method.
Anyway I'll try to post some code when I have time...
Right now the only thing I can show to explain better what I meant is this:

I have a class that's something like this:

class DataContainer(object):
    def __init__(self,data):
        self._data = data
    def data(self):
        return self._data

In my index method (of the model) I do something like this:

def index(self,row,column,parent=QModelIndex()):
    if not parent.isValid():
        return self.createIndex(row,column,None)
        parent_row = parent.row()
        obj = self.manager.get_item(parent_row,row)
        return self.createIndex(row,column,obj)

And my parent method looks like this:

def parent(self,index):
    if not index.isValid():
        return QModelIndex()
    obj = index.internalPointer()
    if obj is None:
        return QModelIndex()
        parent_row = self.manager.index(obj)
        return self.createIndex(parent_row,index.column(),None)

The exception is raised when "self.manager.index" is called;
because the manager class to obtain the index of the object calls "data",
and this call raise an AttributeError like this:

AttributeError: "DataContainer" object has no attribute "_data"

Like if the object wasn't initialized.

I think I'll try to rewrite it following exactly the "simpletreemodel" to
check if it is a bug or if I'm doing something wrong...
Thank you for your attention David.
View this message in context: http://old.nabble.com/Using-QModelIndex.internalPointer-tp26635941p26658308.html
Sent from the PyQt mailing list archive at Nabble.com.

More information about the PyQt mailing list