[PyQt] Threaded communication
Jones, Bryan
bjones at ece.msstate.edu
Tue Feb 17 22:17:42 GMT 2015
Mads,
It depends on your worker thread's code -- is _tasks modifiable at any
time? If so, either approach; if not (I would assume this is the case),
then only by invokeMethod or (perhaps cleaner) via signal/slot connections.
Bryan
On Mon, Feb 16, 2015 at 12:12 PM, Mads Ipsen <mads.ipsen at gmail.com> wrote:
> Hi,
>
> Suppose I have a worker object
>
> class Worker(QObject):
> ...
>
> @QtCore.pyqtSlot(object)
> def addTasks(self, tasks):
> self._tasks.append(tasks)
>
> which has been moved to a QThread using 'moveToThread', and then started
> from there.
>
> * From the main thread, when I add new tasks to the worker, must I
> always use
>
> tasks = ['sleep', 'work', 'run']
> arg = QtCore.Q_ARG(object, tasks)
> Core.QMetaObject.invokeMethod(self._worker, 'addTasks',
> QtCore.Qt.QueuedConnection, arg)
>
> or can I call this directly, like
>
> self._worker.addTasks(tasks)
>
> Observe that I pass a pure Python list from the main thread to the
> worker (not a QStringList).
>
> Best regards,
>
> Mads
>
> --
> +---------------------------------------------------------------------+
> | Mads Ipsen |
> +----------------------------------+----------------------------------+
> | Overgaden Oven Vandet 106, 4.tv | phone: +45-29716388 |
> | DK-1415 København K | email: mads.ipsen at gmail.com |
> | Denmark | map : https://goo.gl/maps/oQ6y6 |
> +----------------------------------+----------------------------------+
> _______________________________________________
> PyQt mailing list PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
--
Bryan A. Jones, Ph.D.
Associate Professor
Department of Electrical and Computer Engineering
231 Simrall / PO Box 9571
Mississippi State University
Mississippi state, MS 39762
http://www.ece.msstate.edu/~bjones
bjones AT ece DOT msstate DOT edu
voice 662-325-3149
fax 662-325-2298
Our Master, Jesus Christ, is on his way. He'll show up right on
time, his arrival guaranteed by the Blessed and Undisputed Ruler,
High King, High God.
- 1 Tim. 6:14b-15 (The Message)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150217/8fea6432/attachment.html>
More information about the PyQt
mailing list