Domanda

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?

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top