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

Phil Thompson phil at riverbankcomputing.co.uk
Sun Feb 6 10:49:45 GMT 2005


On Saturday 05 February 2005 8:34 pm, Christopher J. Bottaro wrote:
> 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.

But you aren't following Qt's threading rules. Only one thread can perform GUI 
operations. You can create the data for the list item in another thread, but 
pass it to the main thread to create the KListViewItem via a custom event.

Phil




More information about the PyQt mailing list