setData raises exit code -1073741819

醉酒当歌 提交于 2019-12-13 05:47:18

问题


I have a subclass of QtGui.QStandardItemModel with setData as follow:

def setData(self, index, value, role):
    if role == QtCore.Qt.EditRole:
        old = self.itemFromIndex(index).text()
        new = value
        MAIN.changeItem(old,new,index)
    return QtGui.QStandardItemModel.setData(self, index, value, role)

In MAIN.changeItem I take the 'old' value and replace it with the 'new' in the Database and and then I setData with the return value. And finally I refresh the Model to show the result. Like so:

def changeItem(self,old,new,index):

    dosomethin(old,newindex) # adjust the database and model

    self.tableUpdate() # refresh/redraw the table

But I'm getting exit -1073741819, but only if I do them one after the other. If I don't refresh the model(commenting out the self.tableUpdate()) but instead do something else that would normaly refresh it(like adding a new item, or changing tabs), it doesn't raise the error. Any idea why is this happening?


回答1:


Oh figured out.

I thought the process would go like:

model.itemChanged.signal -> databaseUpdate() -> setItem() -> tableUpdate()

But instead it was doing:

model.itemChanged.signal -> databaseUpdate() -> tableUpdate() -> setItem()

And since setItem was looking for a index item which was not there anymore(because it got updated), it crashed.

Fixed it by changing the setData return to 'True', or anything.



来源:https://stackoverflow.com/questions/23451176/setdata-raises-exit-code-1073741819

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!