Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. qmqtt QDatastream between Qt and PyQt back and forth
Qt 6.11 is out! See what's new in the release blog

qmqtt QDatastream between Qt and PyQt back and forth

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 1.1k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RahibeMeryem
    wrote on last edited by
    #1

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

    Best

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • R Offline
        R Offline
        RahibeMeryem
        wrote on last edited by
        #3

        PyQt5
        python 3.6

        Pablo J. RoginaP 1 Reply Last reply
        0
        • R RahibeMeryem

          PyQt5
          python 3.6

          Pablo J. RoginaP Offline
          Pablo J. RoginaP Offline
          Pablo J. Rogina
          wrote on last edited by
          #4

          @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

          Upvote the answer(s) that helped you solve the issue
          Use "Topic Tools" button to mark your post as Solved
          Add screenshots via postimage.org
          Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • R Offline
            R Offline
            RahibeMeryem
            wrote on last edited by
            #5

            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__)
                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)
            
            1 Reply Last reply
            0
            • R Offline
              R Offline
              RahibeMeryem
              wrote on last edited by
              #6

              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 ?

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved