当前位置: 动力学知识库 > 问答 > 编程问答 >

python - QSortFilterProxyModel.mapToSource crashes. No info why

问题描述:

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?

网友答案:

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.

网友答案:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: