qmqtt QDatastream between Qt and PyQt back and forth

  • Hi,

    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)
                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 :)


  • Lifetime Qt Champion


    What version of PyQt are you using ?
    What version of Python ?

  • PyQt5
    python 3.6

  • @RahibeMeryem maybe this answer from stackoverflow helps you (Python app publishing a jpg file)

    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[0]
        name = bytearray()
        name.extend(map(ord, result_name))
        result_image = QImage(x[1])
        bytearray__ = QByteArray()
        bio = QBuffer(bytearray__)
        result_image.save(bio, "PNG")
        block = QByteArray()
        xout = QDataStream(block, QIODevice.WriteOnly)
        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 ?

Log in to reply