https://stackoverflow.com/a/22379130/21860235[the post 8 years ago][1]
Hello, I would like to understand what is the trolltech modelest
that he disabled in order to have a fast datachanged.emit(QModelIndex(), QModelIndex())
signal. I don't have a lot of items in my QTreeView
, so it shouldn't take 0,1 seconds each time this signal
is emitted.
Edit
As I said in the comment section, when I remove this line : self.model.dataChanged.connect(self.onDataChanged)
the program works as fast as excpected. This method is not big at all, I only use it to update data in my database (the model is built on this database).
def onDataChanged(self) :
item_id = self.currentIndex().siblingAtColumn(1).data()
if self.currentIndex().isValid() :
new_name = self.currentIndex().siblingAtColumn(0).data()
con : Connexion() = Connexion()
con.update("UPDATE cdc SET nom = :1 WHERE ID = :2",[new_name,item_id])
self.update()
The object con
comes from a class that connects to my database. I tested many queries and they all are fast to commit (less than 0,01 second) so I'm pretty sure the problem does not come from there. So I am wondering if implementing my own dataChanged function is altering Qt's functionnalities ?
Thanks for your answers
I found a way to not get the slowness of the signal dataChanged
as it is directly linked with the setData
method. I saw that connecting to my database is pretty long as I am doing standalones connections. So I created a pool
with the following command : self.pool = oracledb.create_pool(user= self.username, password= self.password, port= self.port, service_name= self.service, dsn= self.dsn, min = 2, max = 2, increment = 0)
. it allows the user to handle 2 connection at the same time. Also, I created another setData method that does not call the dataChanged
signal when it is not necessary. It solved entirely my problem, here is the new method :
def setData2(self, index: QModelIndex, value, role: int) -> bool:
if role != Qt.EditRole:
return False
item: TreeItem = self.get_item(index)
result: bool = item.set_data(index.column(), value)
return result
Hope it solved your issue too !