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 to receive python QVariant(data_dict(..)) from Qt c++ QDatastream QVariantMap?
Qt 6.11 is out! See what's new in the release blog

How to receive python QVariant(data_dict(..)) from Qt c++ QDatastream QVariantMap?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 616 Views 1 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 am creating QVariantMap in python and sending to mqtt:

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

    I try to receive the data from Qt C++ code as below but no succes :

    ....
    ..
    
    QDataStream stream(message)
    stream.setversion(.....)
    
    QVariantMap v_map;
    
    stream  >> v_map;
    

    How can I receive python QVariant(dict) from C++ code as above ? Any idea?

    Thanks/Best

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

      Hi,

      What if you load it directly in a QVariant ?

      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

        @SGaist

        no succes...

        exchanging QVariant between python and C++ could be very usefull..

        Is there anyway to do this ?

        Best

        1 Reply Last reply
        0
        • eyllanescE Offline
          eyllanescE Offline
          eyllanesc
          wrote on last edited by eyllanesc
          #4

          @RahibeMeryem Why don't you convert it to json?

          import json
          
          data = {
              "mq_username": "123",
              "np_database": "png",
              "category": "png",
              "enroll_name": "png",
              "notes": "png",
              "file": "png",
              "np_database": "png",
              "PNG-image": "png",
          }
          
          res = client.publish(test_kanali, json.dumps(data), 2, retain=False)
          
          QVariantMap v_map;
          QJsonDocument doc = QJsonDocument::fromJson(message);
          if(iobj.isObject()){
              QJsonObject obj = doc.object();
              for(const  QString & key: obj.keys()){
                  v_map[key] = obj[key].toVariant();
              }
          }
          qDebug() << v_map;
          

          If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

          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