[PyQt] QThread, Slots, Signals, meta type information error

Repscher, Benedikt Benedikt.Repscher at webasto.com
Mon Mar 4 16:09:52 GMT 2019


Thank you for your reply.
I read the article "you're doing it wrong" and learned some things from it. However, it didn't help me resolve my issue.


I sort of resvoled the issue.
I discovered the difference because the code that I actually use looks a little bit different (uses 2 QThreads). However, this code raised the same error, even though it uses the moveTothread()-approach.


Anyways...
The code that I posted here that uses the moveToThread()-approach works, because the signal belongs to the same object as the slot. Therefore, Qt seems to use a Qt.DirectConnection (non-queued).
However, when you want to use QueuedConnection (which is the default when usign the QThread-subclassing-approach) then the connection fails because of lacking meta-info. 

Therefore, IMHO, the problem with missing meta-info still persists. The moveToThread()-approach just works around the issue, because it doesn't use the queued connection.

Consider the matter closed.

-----Original Message-----
From: Giuseppe Corbelli <corbelligiuseppe at mesdan.it> 
Sent: Monday, March 4, 2019 9:20 AM
To: Repscher, Benedikt <Benedikt.Repscher at webasto.com>; pyqt at riverbankcomputing.com
Subject: Re: [PyQt] QThread, Slots, Signals, meta type information error

On 3/1/19 5:39 PM, Repscher, Benedikt wrote:
> I'm having an Issue regarding QThreads, Slots and Signals and meta type information.
> 
> The Issue arises when I try to connect a signal, e.g.
> QBluetoothDeviceDiscoveryAgent.deviceDiscovered
> to a slot, e.g.
> deviceDiscovered(device)
> where the device is of type QBluetoothDeviceInfo
> 
> The signal-slot connection is done from within a QThread.
> 
> The error that arises is
> QObject::connect: Cannot queue arguments of type 'QBluetoothDeviceInfo'
> (Make sure 'QBluetoothDeviceInfo' is registered using 
> qRegisterMetaType().)

Well, I don't know the internals but the call should be generated by SIP. The QBluetoothDeviceInfo class definition in SIP looks fine at a first glance.

> I've tried generating the meta type info explicitly using char_id = 
> QMetaType.type("QBluetoothDeviceInfo")
> this doesn't help though (and returns 0 anyways)
> 
> 
> What really baffles me is, that this error only occurs when I 
> implement the QThread the traditional way by subclassing QThread and 
> overriding run().
> When I use the approach with the controller that moves the QObject to  
> a QThread (using moveToThread()), then the code works.
I don't see anything wrong with your code, BUT:
https://blog.qt.io/blog/2010/06/17/youre-doing-it-wrong/

--
Giuseppe Corbelli


More information about the PyQt mailing list