views:

311

answers:

2

I have the following code:

proxy_index = self.log_list.filter_proxy_model.createIndex(index, COL_REV)
model_index = self.log_list.filter_proxy_model.mapToSource(proxy_index)
revno = self.log_list.model.data(model_index,QtCore.Qt.DisplayRole)
self.setEditText(revno.toString())

The code crashed on the second line. There is no exception raised. No trace back. No warnings. How do I fix this?

A: 

It may be that you're using the proxy model's createIndex() method incorrectly. Usually, the createIndex() method is called as part of a model's index() method implementation.

Have you tried calling the proxy model's index() method to get a proxy index then mapping that to the source?

Perhaps you could show the code in context or explain what you are trying to do.

David Boddie
A: 

I've run into the same problem, but fortunately using the index () method instead of createIndex () as David recommends does the magic. In general it's a bad idea to mess around with the internal pointer of QModelIndex outside the index () method. Even when using your own Model messing around the internal pointer leads often to unexpected bahavior since Qts View code is pretty obscure to the user.

count0