1

Platform: Centos 6 & Python 2.6.6

After looking at every example and question about doing this, for the life of me I can't get it to work on my system. Most answers seem to revolve around using PyQt instead of PySide, which isn't an option for me: I gotta use what the company gives me.

Here is the code snippet from my main GUI application:

from PySide import QtCore, QtGui
class MyGui( QtGui.QMainWindow ):
  @QtCore.Slot( dict )
  def MySlot( self, data ):
     CodeThatUsesData()

And the module that emits the signal:

from PySide.QtCore import *
from PySide.QtGui  import *
class QListener( QThread ):
  MySignal = Signal( dict )

def DoSomeWork( self ):
  data = {'a':1, 'b':2}
  self.MySignal.emit( data )

And of course I've got code that connects the signal and the slot:

listener.MySignal.connect( gui.MySlot )

And the error I get when DoSomeWork() is called (specifically at the emit() line) is this:

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

From what I've read, this should totally work. More frustrating is I've found PySide documentation alluding to the use of qRegisterMetaType, but I can't find out where to call it from. It isn't in QtCore or QtGui, or stand-alone, or a member of QMainWindow or QThread or QObject.

So how do I register 'object' as a valid type for passing via the Signal/Slot paradigm? I've even tried wrapping the dictionary inside a QObject class, and that removes the registration error but the Slot operation is never called, so I don't know where the data is actually going.

I feel like the solution is slapping me in the face, but I can't see the "missing semi-colon". I'm about ready to just use the signal to indicate to the GUI that there is something in a shared queue for it to pull off - a less than elegant solution.

For completeness, here are similar posts that I've read but haven't helped me:

stackoverflow: sending-custom-pyqt-signals

stackoverflow: Qt: Not registered qRegisterMetaType()

stackoverflow: QObject (QPlainTextEdit) & Multithreading issues

stackoverflow: QObject::connect: Cannot queue arguments of type 'object' in PySide

TIA stackoverflow community!

Community
  • 1
  • 1
PfunnyGuy
  • 750
  • 9
  • 22
  • Does this [previously asked question](http://stackoverflow.com/questions/2585442/sending-custom-pyqt-signals) contain the answer you're looking for? – sytech Jun 28 '16 at 22:03
  • 1
    I cannot reproduce this problem using PySide-1.2.4. Presumably, CentOS 6 has a much older version of PySide which is buggy. What exact version are you using? – ekhumoro Jun 29 '16 at 01:03
  • @Gator_Python: That doesn't help, as it cites using pieces that are PyQt specific and I'm stuck with PySide. – PfunnyGuy Jun 29 '16 at 02:45
  • @ekhumoro: I don't know. I did a dir(PySide) and there is no __version__ to get, so "Old" is probably the answer. I'll see about updating that. Edit: 'yum' says version 0.4.1. 0.o That just hurts my brain... – PfunnyGuy Jun 29 '16 at 02:50
  • PySide.QtCore.QSettings.qRegisterMetaType -- Couldn't find any usage examples. But appears to be there. But not sure why you're having a problem. – sytech Jun 29 '16 at 04:40
  • As an alternative, sending the data to an instance of Queue.Queue(), and emitting a signal to indicate new data, and reading the data from the queue, might work. – J.J. Hakala Jun 29 '16 at 10:58
  • @JJ: That is my back up plan, but it's not the right way to do it, just a work-around. The struggle brings understanding, so I've been forcing myself to struggle through this, see if I can make it work the correct way. – PfunnyGuy Jun 29 '16 at 13:36
  • @Gator_Python: Thanks! That's the path to qRegisterMetaType I was looking for. I couldn't figure out where it was, couldn't find documentation, and what just dawned on me, I couldn't think outside the box to write a bit of Python to do a dir() on PySide and everything in it to locate qRegisterMetaType. I wish I had thought of that many hours ago. Having done that, qRegisterMetaType is not in the older-than-dinosaurs ver 0.4.1 PySide I'm currently crippled with. So I'll investigate upgrading PySide, and if I can't then I'll toss in a Queue for dictionary passing. Thanks all! – PfunnyGuy Jun 29 '16 at 14:00
  • @PfunnyGuy - Glad I could help. I'll stick that in an answer if you want to mark it. It wasn't well-documented. I would look at the QtCore.QSettings docs for more information. - Cheers – sytech Jun 29 '16 at 15:46
  • @PfunnyGuy. What is the output of: `python -c 'import PySide; print(PySide.__version__)'`? – ekhumoro Jun 29 '16 at 16:43
  • @ekhumoro - my PySide is so old there is no __version__! That's what I meant in my first reply to you. PySide.__version__ = 'module' has no attribute '__version__' – PfunnyGuy Jun 29 '16 at 17:13
  • @PfunnyGuy. Ah - you should have enclosed it in backticks, otherwise the underscores get interpreted as bold. I only asked, because pyside-0.4.1 would have already been old when centos was released in mid-2011, so it didn't seem plausible. – ekhumoro Jun 29 '16 at 18:16

1 Answers1

1

The following is the location of that method, according to the docs. As mentioned in comments, you should upgrade PySide to the latest version as the issue you're having was not reproducible in the current version.

PySide.QtCore.QSettings.qRegisterMetaType

sytech
  • 29,298
  • 3
  • 45
  • 86
  • Where are you getting this from? `qRegisterMetaType` is not a member function of `QSettings` or any other class. It is part of [QMetaType](http://doc.qt.io/qt-4.8/qmetatype.html), which is not implemented by PySide. If you are using a version of PySide that somehow exposes `qRegisterMetaType`, it's a bug. There is no use case for implementing `qRegisterMetaType`, because `PyObject` is automatically registered in the metatype system by PySide. – ekhumoro Jun 29 '16 at 18:00