Results 1 to 2 of 2

Thread: How to access key and value in QvariantMap?

  1. #1
    Join Date
    Jul 2016
    Posts
    53
    Thanks
    13
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default How to access key and value in QvariantMap?

    Hi,

    I had assigned the value from the Json to QvariantMap. I can see the values are stored in Key and Value pairs.
    Query: How to fetch the value?

    in main.qml

    var jsontext = '[{"firstname":"Jesper","surname":"Aaberg","phone":" 555-0120"},{"firstname":"Jesperuu","surname":"Aaberguu ","phone":"55665-0120"}]';


    Qvari.jpg

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to access key and value in QvariantMap?

    In C++ you can use either the index operator or the value method to do a key lookup.
    E.g.
    Qt Code:
    1. QVariant someValue = variantMap.value(someKey);
    To copy to clipboard, switch view to plain text mode 

    In QML/JavaScript I think you can also use the index operator or the key as a property name,
    e.g.
    Qt Code:
    1. var someValue = variantMap[someKey];
    To copy to clipboard, switch view to plain text mode 

    The script environment can also deal with JSON directly as far as I know.

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    Mathan (28th September 2016)

Similar Threads

  1. Accessing Multiple Levels of QVariantMap
    By micgooapp in forum Qt Programming
    Replies: 3
    Last Post: 8th June 2013, 10:43
  2. Convery QByteArray to QVariantMap
    By karankumar1609 in forum Qt Programming
    Replies: 3
    Last Post: 30th May 2013, 21:19
  3. Traversing QVariantMap
    By ggdev001 in forum Newbie
    Replies: 9
    Last Post: 7th February 2013, 17:07
  4. Replies: 0
    Last Post: 10th December 2011, 11:17
  5. QVariant, QVariantMap, and QFileInfoList
    By themolecule in forum Qt Programming
    Replies: 2
    Last Post: 13th September 2007, 07:00

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.