[PyKDE] Adding QListViewItems from a thread

Boudewijn Rempt boud at valdyas.org
Tue Feb 25 09:19:01 GMT 2003


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Tuesday 25 February 2003 09:08, Mike Kinton wrote:
> I have a function in the main thread that adds an item to a QListView.  If
> called from the main thread, this works fine.  However if I call this same
> function from a separate thread, the items are displayed in the lsit view,
> but QlistView seems to lose the pointer(s) to the items in QListView.
>
> I have used the python thread module and have not put any locking in.
>
> this is my first effort at using of threads so I may have made some silly
> mistake.

Well, in almost all GUI libraries, you can only do things with the
gui from the main thread. Your best bet would be a producer/consumer
model with a Queue: have the sub thread add commands to a Queue that
the main thread reads out and handles. See for some more discussion
my recent article on www.informit.com (no permalink, I'm afraid,
but if you login and search for my name, you'll find it).

- -- 
Boudewijn Rempt | http://www.valdyas.org/index2.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE+WybgdaCcgCmN5d8RAvfQAKCpI1LFryjP3DuJhWl/mx0X+PS7BgCgzo0f
pWjktt2yir1QGvfnhrbz28Q=
=jxLi
-----END PGP SIGNATURE-----




More information about the PyQt mailing list