[PyQt] Threaded communication

Mads Ipsen mads.ipsen at gmail.com
Mon Feb 16 18:12:35 GMT 2015


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 |
+----------------------------------+----------------------------------+


More information about the PyQt mailing list