[PyQt] Problem with implementation of dummy (no-op) proxy model

Hans-Peter Jansen hpj at urpla.net
Wed Oct 27 21:17:30 BST 2010


On Wednesday 27 October 2010, 20:34:18 Hans Meine wrote:
> Hi,
>
> I am having lots of crashes with my implementation of a dummy proxy
> model. Could someone please look at this and tell me at which point I
> am being stupid (and blind) or whether this is a problem with [Py]Qt?
>
> I have attached a stripped down test case that crashes for me (i.e.
> segfault/ bus error/glibc double free).

Not here. After fixing the obvious bug in headerData to actually call 
headerData, I get (with needPersistentModelIndex = False):

1) rowCount: 10

2) got root index <PyQt4.QtCore.QModelIndex object at 0x8175d4c> 
(isValid: True)

3) got base index <PyQt4.QtCore.QModelIndex object at 0x8175d14>

and

1) rowCount: 10

2) got root index <PyQt4.QtCore.QModelIndex object at 0x8175d14> 
(isValid: True)

Traceback (most recent call last):
  File "dummy_proxy.py", line 99, in <module>
    j = model._baseIndex(i)
  File "dummy_proxy.py", line 21, in _baseIndex
    baseIndex.row(), baseIndex.column(), baseIndex.parent())
RuntimeError: underlying C/C++ object has been deleted

for the other variant.

> For now, I just want to have a model that wraps another model and
> forwards all calls (for future expansion of course).  Could there be
> a simpler model?
>
> There are two obvious ways to implement such a proxy model, one is to
> let the internalPointer() point to the corresponding model index of
> the proxied Views model, and one is to let the internalPointer()
> point to the corresponding *parent* model.
>
> The former leads to slightly simpler code in the pure dummy model
> case, but leads to a duplication of the row/column information. 
> Although this is quite ugly, I attached this (simpler) variant.
>
> I am getting crashes when accessing internalPointer(), as I can see
> by single- stepping through the code in pdb.  I also tried using
> QPersistentModelIndex for the internalPointer() (although I am just
> dealing with static models), but that did not resolve the crashes
> either.

I must confess, that I don't grok your _baseIndex, index and parent 
methods for the persistant index case, especially the 

		baseIndex = self._baseModel.index(
                        baseIndex.row(), baseIndex.column(), 
      			baseIndex.parent())

but I'm really tired already..

The real question is, why don't you base your proxy model on 	
QProxyModel, it's made exactly for your aspired purposes, AFAICS.
If you really want to bake your own, I would start with a C++->Python 
conversion of that module, and enhance as required. 

> In the attached test case, in which I set up a QStringListModel for
> testing, it additonally fails with "TypeError:
> QAbstractListModel.parent() is a private method".   (Maybe I am too
> tired now, but that looks like a bug in QAbstractListModel to me;
> parent() should not be private.)

I guess, this is triggered from former errors.

Good luck,
Pete

Hehe, outcome from my early in the morning gizmos ;-):
python: 2.6
sip: 4.12-snapshot-12acbffd0085
qt4: 4.7.0
pyqt4: snapshot-4.8.1-620cc57dc977


More information about the PyQt mailing list