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. How can I read QVariantMap send from Pyqt5 ia QDataStream ?

How can I read QVariantMap send from Pyqt5 ia QDataStream ?

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 4 Posters 619 Views
  • 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 RahibeMeryem
    #1

    I have QVariant Map in python:

    data = {'mq_username': ('123'),  'np_database': ('png') ,  'category': ('png') ,  'enroll_name': ('png') ,  'notes': ('png') ,   'file': ('png') ,
                'np_database': ('png') , 'PNG-image': (png) }
        v = QVariant(data)
        block = QByteArray()
        xout = QDataStream(block, QIODevice.WriteOnly)
        xout.setVersion(qt.QDataStream.Qt_5_10)
        xout << v
        xox = (b'')
        xox = block.data()
        res = client.publish(test_kanali, xox, 2, retain=False)
    

    receving perfectly from mqt in python and can deserialize :

                block = qt.QByteArray(message.payload)
                out = qt.QDataStream(block, qt.QIODevice.ReadOnly)
                out.setVersion(qt.QDataStream.Qt_5_10)
    
                keys = out.readQVariant()
    

    But I cant figure aout how to do in c++ ?

            QVariantMap vmat_x;
    
            QDataStream stream(message);
            stream.setVersion(QDataStream::Qt_5_10);
            stream >> vmat_x ;
    

    vmat_x is alway empty ?

    Best

    1 Reply Last reply
    0
    • R RahibeMeryem

      @Christian-Ehrlicher I have python client that read the same data correctly. SO data is arriving properly and can be read from python client as Qvariantmap.

      Problem is at the c++ side

      Best

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #10

      @RahibeMeryem
      The problem is really at the Python side, not the C++ side. If you intend to share with C++, you cannot afford to write any Python-object-type into the stream; it looks like you have written a PyQt_PyObject, and that would mean it is only readable by PyQt5.

      1 Reply Last reply
      1
      • Christian EhrlicherC Online
        Christian EhrlicherC Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @RahibeMeryem said in How can I read QVariantMap send from Pyqt5 ia QDataStream ?:

        vmat_x is alway empty ?

        Because you try to read a pointer instead an object.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

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

          @Christian-Ehrlicher sorry its not pointer I fixed.

          I cant read anything now also.

          BC

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

            Hi,

            IIRC, you have to read it into a QVariant and then you can extract the QVariantMap.

            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
            1
            • Christian EhrlicherC Online
              Christian EhrlicherC Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #5

              @SGaist said in How can I read QVariantMap send from Pyqt5 ia QDataStream ?:

              you have to read it into a QVariant and then you can extract the QVariantMap.

              You're right - I've overseen that he adds a QVariant, not a QVariantMap.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

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

                @Christian-Ehrlicher @SGaist

                void MainWindow::mq_message_received(const QByteArray &message, const QMqttTopicName &topic) {
                
                //message is the mqt received from Python created QDatastream
                
                        QDataStream stream(message);
                        stream.setVersion(QDataStream::Qt_5_10);
                        QVariant vmat_t;
                        stream >> vmat_t ;
                        
                  //Convert to QVariantMap
                
                
                
                }
                

                I have nothing in the vmat_t QbyteArray.
                Would you mind to show me an example How can I get this stream as finally QVarianMap ?

                Best
                Thanks

                1 Reply Last reply
                0
                • Christian EhrlicherC Online
                  Christian EhrlicherC Online
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #7

                  @RahibeMeryem said in How can I read QVariantMap send from Pyqt5 ia QDataStream ?:

                  I have nothing in the vmat_t QbyteArray.

                  First you should make sure that the data you're sending arrive at your receiver by e.g. output the bytearray you send you you receive

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  1 Reply Last reply
                  1
                  • R Offline
                    R Offline
                    RahibeMeryem
                    wrote on last edited by
                    #8
                    stream >> vmat_t ;
                    
                    QVariant::load: unknown user type with name PyQt_PyObject.
                    

                    The error

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

                      @Christian-Ehrlicher I have python client that read the same data correctly. SO data is arriving properly and can be read from python client as Qvariantmap.

                      Problem is at the c++ side

                      Best

                      JonBJ 1 Reply Last reply
                      0
                      • R RahibeMeryem

                        @Christian-Ehrlicher I have python client that read the same data correctly. SO data is arriving properly and can be read from python client as Qvariantmap.

                        Problem is at the c++ side

                        Best

                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on last edited by JonB
                        #10

                        @RahibeMeryem
                        The problem is really at the Python side, not the C++ side. If you intend to share with C++, you cannot afford to write any Python-object-type into the stream; it looks like you have written a PyQt_PyObject, and that would mean it is only readable by PyQt5.

                        1 Reply Last reply
                        1

                        • Login

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