2

I am using PySide (Python Qt binding).

I have a worker thread of class QThread that updates the main GUI thread (updates the QTableWidget) through signal/slot mechanism.

In my worker thread, I have the following:

self.emit(SIGNAL("alterTable(object"), params)

In my GUI thread I have this:

self.connect(self.worker, SIGNAL("alterTable(object)"), self.updateMainTable, Qt.AutoConnection)

Since there are several similar worker threads running all connecting to the same slot (the self.updateMainTable), I should use the AutoConnection (and consequently the QueuedConnection). Using the Qt.DirectConnection works, but it is not safe (or so I have been told).

But when I try to use the AutoConnection, I get the following error:

QObject::connect: Cannot queue arguments of type 'object'
(Make sure 'object' is registered using qRegisterMetaType().)

I have Googled for eons trying to figure out a way how to use the qRegisterMetaType() in PySide, to no avail. All the resources I found online point to a C++ syntax/documentation.

If it makes any difference, the object in question is a dict most of the time.

Bo Milanovich
  • 7,995
  • 9
  • 44
  • 61

2 Answers2

1

I guess I have found an answer myself, well not exactly an answer, but a workable solution.

I switched all the Signals to the new-style syntax. In case anyone is wondering, I did that by defining a custom signal in my worker class. So my code looks something like this

class Worker(QThread):

    alterTable = Signal(dict)

    def __init__(self, parent=None):
        ....
        self.alterTable.emit(parameters)


class GUI(QMainWindow):

    def __init__(self, parent=None):
        WorkerModule.Worker().alterTable.connect(self.myMethod)

For some reason the Signal has to be inside the QThread class; otherwise, Qt complains about "Signal has no attribute connect" error, which is very weird.

Bo Milanovich
  • 7,995
  • 9
  • 44
  • 61
1

Incredibly late for the answer here, my apologies. Not enough reputation to add a comment to your accepted answer. I hope this might help new PySide/Pyside2 users who stumble upon your issue.

Issue: QObject::connect: Cannot queue arguments of type 'object'

Solution: self.connect(self.worker, SIGNAL("alterTable(PyObject)"), self.updateMainTable, Qt.AutoConnection)

Issue: Qt complains about "Signal has no attribute connect" error

Solution: The connect attribute is implemented in QObject, so you must first call the parent's init method through either QMainWindow.__init__(self) or super(GUI, self).__init__() (Py2) or also super().__init__() (Py3).

Cheers.