[PyQt] Populate Model data in a separate thread

Detlev Offenbach detlev at die-offenbachs.de
Mon Apr 27 18:00:15 BST 2009


Another solution would be to do lazy population of the model. That is, if 
child items are to be shown, fetch them at that time. This avoids populating 
the model in advance and is more responsive. See eric4 as an example.

Detlev

On Montag, 27. April 2009, Demetrius Cassidy wrote:
> How many items do you need to populate in your model class? Unless you are
> populating a view with thousands of items, I do not suggest threads at all
> since they can be dangerous if you do not know how to use them.
>
> If you absolutely needed to do this, my approach would be to have some sort
> of method I could call on my dialog to fetch items in a separate thread in
> the model, and once I have my data I could populate myself and call the
> appropriate begin/end methods on my QAbstractItemModel class.
>
> If I knew what you were trying to accomplish, then maybe I could give you
> some better guidance.
>
> Edwin Marshall-2 wrote:
> > I've been reading on qtcentre that it is possible to populate a model
> > from a separate qthread in order to prevent a program from freezing
> > before it loads, however the example code I have seen is a bit too much
> > involved (and in c++) for me to comprehend. I was wondering if anyone
> > knew of a pyqt program that did, or could point me toward some code
> > snippets doing this. The only thing that I can gather is that I need to
> > create the qthread in the __init__ method of my model and call it's run
> > command. However, I can't figure out what exactly need to go in the run
> > method, or what signals to emit/catch. Thansk in advance for any help
> >
> >
> >
> >
> > _______________________________________________
> > PyQt mailing list    PyQt at riverbankcomputing.com
> > http://www.riverbankcomputing.com/mailman/listinfo/pyqt



-- 
Detlev Offenbach
detlev at die-offenbachs.de


More information about the PyQt mailing list