-3

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

Thomas.C
  • 7
  • 5
  • 1
    Why not ask with your own problem description and [mre]? Anyway, see [Model Test](https://wiki.qt.io/Model_Test). – relent95 Jun 23 '23 at 00:37
  • I wonder if "modelest" is typo for "model test"? – hyde Jun 23 '23 at 09:07
  • @relent95 my program is getting bigger so it is hard to make an MRO with it. I am trying to make one currently, I'll edit my post when it is finished. Now, I tried many tests to see what slows my program and it appears that when I comment this : `self.model.dataChanged.connect(self.onDataChanged)` , it goes way faster ! Check the edit of the post to see what this method does in my program – Thomas.C Jun 23 '23 at 12:24
  • @relent95 I made an [MRO](https://stackoverflow.com/help/minimal-reproducible-example) but I can't see the problem as it works well. I am thinking if the issue comes from the fact that I have many `QTreeView` but I really don't now. Anyway, I created a `setData2` method to go around the problem. Is it a good idea to post it as an answer or should I just delete the post ? – Thomas.C Jul 06 '23 at 07:13
  • I recommend to delete the question, because it does not help others in this state. You can read deleted questions from the Activity tab of your profile page. – relent95 Jul 06 '23 at 11:09
  • @relent95 alright, thank you – Thomas.C Jul 06 '23 at 12:01

1 Answers1

0

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 !

Thomas.C
  • 7
  • 5