Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
qmqtt QDatastream between Qt and PyQt back and forth
I can send Qdatastream (Qstring + Png) to python with qmqtt thwough broker and succesfully decode them in python with below code:
data_ is coming from paho mqt client
data_ = model_worker_queue.get() out = qt.QDataStream(data_, qt.QIODevice.ReadOnly) out.setVersion(qt.QDataStream.Qt_5_10) png = out.readBytes() text = out.readQString()
All is good:
But I couldn find a way to send back Qdatastream message to the Qt C++ through paho mqt client.
I create Qbytearray but client asking bytes
how can I pack image + text in python and send through mqt to Qt C++ and decode there ?
struggled half day and forgetting now what I now :)
What version of PyQt are you using ?
What version of Python ?
Pablo J. Rogina last edited by
Just to be sure, you have 2 Python applications right? One subscriber (from the code you posted) receiving the image from Qt C++, and another Python app (perhaps the same but acting) as publisher which will read a jpg file and send data to Qt C++ subscriber
two app : c++ and python:
I manage this way to send python to c++:
result_name = x name = bytearray() name.extend(map(ord, result_name)) result_image = QImage(x) bytearray__ = QByteArray() bio = QBuffer(bytearray__) bio.open(QIODevice.WriteOnly) result_image.save(bio, "PNG") block = QByteArray() xout = QDataStream(block, QIODevice.WriteOnly) xout.setVersion(qt.QDataStream.Qt_5_10) xout << QByteArray(result_name.encode('utf-8')) << bytearray__ xox = (b'') xox = block.data() res = publisher.publish("result/light", xox , 2, retain=True)
Now I have re-connecting issue.
when my c++ qmqtt client disconnected , I cant re-connect . its hanging on the state 1.
What is the proper way to reconnect ?