Discussion:
Qt.Queuedconnection queue size
Dirk Wagener
2007-10-11 08:54:35 UTC
Permalink
Hi

I have a signal that is emitted from one thread to another. I wire it as
follows:

QtCore.QObject.connect( self.__model, QtCore.SIGNAL("TestSignal"),
self.callable1,
QtCore.Qt.QueuedConnection )

* How do I limit the size of the queue used for the queuedconnection in
this case?

* When the signal is emitted by one thread, an image is passed to the
slot. When the slot does not service the signals
quick enough, the memory usage starts climbing because of the queue just
growing and growing.

* Is it possible to set the queue size for just one specific signal to
slot connection?

Kind regards
Dirk Wagener
--
Dirk Wagener <***@stonethree.com>
(MSc. Electronic Engineering, Stell.)

Project Engineer
Stone Three Signal Processing (Pty.) Ltd.
http://www.stonethree.com
+27 21 851 3123 (phone)
+27 21 851 3127 (fax)


We shall not cease from exploration and the end of all our exploring will
be to arrive where we started... and know the place for the first time.
T.S. Eliot
Phil Thompson
2007-10-11 09:25:21 UTC
Permalink
Post by Dirk Wagener
Hi
I have a signal that is emitted from one thread to another. I wire it as
QtCore.QObject.connect( self.__model, QtCore.SIGNAL("TestSignal"),
self.callable1,
QtCore.Qt.QueuedConnection )
* How do I limit the size of the queue used for the queuedconnection in
this case?
* When the signal is emitted by one thread, an image is passed to the
slot. When the slot does not service the signals
quick enough, the memory usage starts climbing because of the queue just
growing and growing.
* Is it possible to set the queue size for just one specific signal to
slot connection?
No - the "queue" is the event queue used by the event loop.

You need something like an image cache (protected my mutexes). Place the image
in the cache and pass the index (or hash or whatever value you use as the
reference of the image in the cache) to the slot. If the cache is too big,
discard old images. When the slot fires it looks for the image and does
nothing if it is no longer in the cache.

Note that there is no need to specify a queued connected. All connections
across threads are queued.

Phil
Andreas Pakulat
2007-10-11 11:12:11 UTC
Permalink
Post by Phil Thompson
Note that there is no need to specify a queued connected. All connections
across threads are queued.
Thats only true if either PyQt4 differs from Qt4/C++ in this respect or
the two objects involved in the connection live in two different
threads. That is usually not the case for the QThread (or subclass)
object that you create in your main thread, only objects created in its
run() method live in that new thread. Of course there's moveToThread()
to change the owning thread of an object.

Andreas
--
Tuesday is the Wednesday of the rest of your life.
Loading...