[PyQt] Can't pass a dict to a signal that expects QJsonObject

Davi Ramos davirtavares at gmail.com
Fri Jul 7 13:58:44 BST 2017


Versions of PyQT tested: 5.8.2 and 5.9

Basically there is a signal on QWebChannelAbstractTransport called
"messageReceived" and it's signature is as follow:

void messageReceived(const QJsonObject &message,
QWebChannelAbstractTransport *transport)

According to PyQt documentation, QJsonObject is internally converted to
"dict", but when I try to emit that signal passing a dict that was returned
from QJsonDocument.object(), it fails:

message = QJsonDocument.fromJson(messageData.encode("utf-8"), parser_error)
self.messageReceived.emit(message.object(), self)

Traceback (most recent call last):
  File "main.py", line 54, in textMessageReceived
    self.messageReceived.emit(a, self)
TypeError: messageReceived(self, Dict[str, Union[QJsonValue,
QJsonValue.Type, Iterable[QJsonValue], bool, int, float, str]],
QWebChannelAbstractTransport).emit(): argument 1 has unexpected type 'dict'
Aborted

I tried passing an empty dict {} and it worked (although it failed later
cause of other reasons, but the signal was emitted).

A better context is provided here: https://pastebin.com/knJr26Rj

--
Davi R. Tavares
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20170707/34cc5ac3/attachment.html>


More information about the PyQt mailing list