Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to pack the c++ data into QVariant Object list
QtWS25 Last Chance

How to pack the c++ data into QVariant Object list

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 1.3k 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.
  • E Offline
    E Offline
    econtech
    wrote on last edited by
    #1

    In C++ I am having list of int,QStringList value for the object. I want to pack it in the QVariant Object list and access into the QML.

    I tried to access the qml i am not able to get the object properties.

    How can I unpack the data from the QVariant having QVariant list of QObject from c++ to QML. Its very helpful any one of you help me,how i can proceed.

    Thanks In Advance

    1 Reply Last reply
    0
    • E Offline
      E Offline
      econtech
      wrote on last edited by
      #2

      Can any one of you help me for the above question

      1 Reply Last reply
      0
      • E Offline
        E Offline
        econtech
        wrote on last edited by
        #3

        I am having the the list of items like QStringList, QString,int in c++ class. How I can pack all the data into object list and send to qml.

        I tried but i am not getting the values in QML.
        How i can send the data from c++ to qml and access all the element in the list in QML.

        Can any one of you give idea its very helpful.

        Thanks in advance

        1 Reply Last reply
        0
        • shavS Offline
          shavS Offline
          shav
          wrote on last edited by
          #4

          Hi,

          You can use code like this:
          @
          QVariant getVaraintObect() //This method must have prototype with Q_INVOKABLE macros in you C++ class.
          {
          QVariantMap map;
          map["key1"] = list; //your QVariantList object with items.
          map["key2"] = 20; //your int value.
          //....
          return QVariant(map); //The method return QVariant object.
          }
          @

          In QML you call the method of your class which must to return to you your QVaraint object, for example:
          @
          Text {
          text: yourCPPObject.getVaraintObect().key2.
          }
          @

          In result you must see 20 in Text element of your QML file.
          Also you can use console.log to print all structure of object:
          @
          console.log(yourCPPObject.getVaraintObect());
          @

          In result you must must see something like this:
          @
          {"key1": [], "key2": 20}
          @

          Mac OS and iOS Developer

          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