[PyKDE] Re: crash after populating list view from separate thread

Christopher J. Bottaro cjbottaro at alumni.cs.utexas.edu
Sat Feb 5 20:34:16 GMT 2005


Christopher J. Bottaro wrote:

> My my program starts up, I have to populate a list view.  There are many
> items (over 5000), so I opted to do it in a separate thread.  Now, I'm
> pretty new to QT (and KDE) programming, so I suspect I'm doing this
> "wrong".  Please take a look and see...
> 
> ---
> 
> class PopulatingThread(QThread):
>    def __init__(self, prog):
>       QThread.__init__(self)
>       self.prog = prog
> 
>    def run(self):
>       self.prog.PopulateListView()
> 
> class MyProg(KMainWindow):
>    def __init__(self, *argv):
>       KMainWindow.__init__(self, *argv)
>       self.list_view = KListView(...)
>       self.list_view_search = KListViewSearchLine(..., self.list_view)
>       self.thread = PopulatingThread(self)
>       self.thread.start()
> 
>    def PopulateListView(self):
>       for item in some_item_list:
>          KListViewItem(self.list_view, item)
> 
> ---
> 
> The problem is that when the thread finishes, the program crashes.  The
> program doesn't crash if I call PopulateListView() directly from
> __init__(), but then of course GUI locks up, progress bars don't
> completely show, etc.
> 
> Any ideas?  Thanks for the help.

P.S.  I'm using python-2.3.4 and sip-4.1.1.  My main thread says "from qt
import *", so as far as I can tell, I'm following the threading rules as
outlined by the PyQT documentation.




More information about the PyQt mailing list