[PyQt] Re: Re: segfault when using a proxy and SIGNAL( "clicked(QModelIndex)" )

TP paratribulations at free.fr
Tue Apr 14 10:26:44 BST 2009

Andreas Pakulat wrote:

> The reason you get a segfault when using a proxy is quite simply that
> you're trying to access something which doesn't exist. The index you get
> in cellClicked is not an index of your custom model, its an index of the
> proxy model, which doesn't have an internal pointer (or maybe it does,
> but its not what you expect). Whenever you get an index from a view or
> selection model and you're using proxy models, you first have to convert
> from the proxy index into a source index via mapTosource() from
> QAbstractProxyModel.

Ok, it works perfectly. Just replace the cellClicked function by:

    def cellClicked( self, qmodelindex ):

        if qmodelindex.isValid():
            qmodelindex = self.proxyModel.mapToSource( qmodelindex )
            print qmodelindex.internalPointer()

python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\

"When a distinguished but elderly scientist states that something is
possible, he is almost certainly right. When he states that something is
impossible, he is very probably wrong." (first law of AC Clarke)

More information about the PyQt mailing list