setData引发退出代码-1073741819 [英] setData raises exit code -1073741819

查看:172
本文介绍了setData引发退出代码-1073741819的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个QtGui.QStandardItemModel的子类,具有setData,如下所示:

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)

在MAIN.changeItem中,我使用旧"值,并在数据库中将其替换为新",然后使用返回值setData.最后,我刷新模型以显示结果.像这样:

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

但是我要退出-1073741819,但前提是我一个接一个地做.如果我不刷新模型(对self.tableUpdate()进行注释),而是执行其他通常可以刷新模型的事情(例如添加新项或更改选项卡),则不会引发错误.知道为什么会这样吗?

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?

推荐答案

哦,想通了.

我认为该过程将如下:

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

但是它正在做:

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

并且由于setItem正在寻找不再存在的索引项(因为它已更新),因此崩溃了.

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

通过将setData返回值更改为"True"或其他任何内容来修复该问题.

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

这篇关于setData引发退出代码-1073741819的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆