[PyQt] QTreeView + sort + delete = crash

Kyle Altendorf sda at fstab.net
Tue May 7 18:21:18 BST 2019


On 2019-05-07 12:13, John F Sturtz wrote:

> Thanks again Florian.  I'll see if I can get anywhere with this.
> 
> This is Windows, so I can't use gdb, I don't think.  I see your 
> instructions for Windows say something about running a diag tool on a 
> dump file.  Unfortunately, I don't get an _"Xxx has stopped working"_ 
> window, so I'm not sure I have the capability to create a dump file.
> 
> But perhaps the faulthandler module will enlighten me.
> 
> I keep thinking it must have something to do with sorting the data 
> underlying the model -- that maybe it causes Qt to get confused as to 
> what model index corresponds to what data item.  In any event, it seems 
> definitely to be the case that if I comment the sort out, the crash 
> disappears ...

Is this really all you do when you sort?

     # Sort children
     def sort_children(self):
         self.children.sort(key=lambda x: x.desc())
         return

Yes, that would upset Qt very much.  You would need to do a series of 
moves or a restructure or...  I'm forgetting the terms offhand.  But 
yes, you have to tell Qt when stuff moves around.  This would be part of 
why it's useful to let an entirely stock Qt object like a proxy take 
care of it for you.

Cheers,
-kyle


More information about the PyQt mailing list