Results 1 to 4 of 4

Thread: Accessing Multiple Levels of QVariantMap

  1. #1
    Join Date
    Dec 2012
    Posts
    9
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Accessing Multiple Levels of QVariantMap

    I wanted to create multidimensional arrays in QT.
    I am trying to use QVariantMap to do so :
    Qt Code:
    1. QVariantMap v;
    2. v["lang"] = 1;
    3. v["test"] = 1;
    To copy to clipboard, switch view to plain text mode 

    The above code works, but when I try to create another level of array, it doesnt work.
    Qt Code:
    1. QVariantMap v;
    2. v["test"]["test"] = 1;
    To copy to clipboard, switch view to plain text mode 

    How should I get this to work in QT ?
    I need this functionality to insert as well as retrieve data from the Map.
    I know its possible to create another QVariantMap first and then insert it into the MAP again :
    Qt Code:
    1. QVariantMap v;
    2. QVariantMap test;
    3. test["a"] = 1;
    4. test["b"] = 2;
    5. v["test"] = test;
    To copy to clipboard, switch view to plain text mode 

    However in the above code, I am not able to modify the values of the nested map again like v["test"]["b"] = 3;

    Is there anyway to achieve this ?

  2. #2
    Join Date
    Dec 2012
    Posts
    9
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Accessing Multiple Levels of QVariantMap

    I have been thinking if I can inherit the QVariant class and modify the [] operator.
    I am not an expert with QT classes and hence if anyone can guide me on this, it will be great.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Accessing Multiple Levels of QVariantMap

    The problem you have is because of the fact that QVariantMap is really a QMap<QString,QVariant> therefore calling v["x"] returns a QVariant and not a QVariantMap so it doesn't have the index operator.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    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: Accessing Multiple Levels of QVariantMap

    It could be helpful to know what task you are trying to solve. Maybe there is a more suitable way doing it than QVariantMap

    Cheers,
    _

Similar Threads

  1. Traversing QVariantMap
    By ggdev001 in forum Newbie
    Replies: 9
    Last Post: 7th February 2013, 17:07
  2. KDChart: add horizontal lines (levels/markers)
    By galrub in forum KDE Forum
    Replies: 0
    Last Post: 5th August 2012, 18:02
  3. type casting 5 levels down no error but not proper
    By sujan.dasmahapatra in forum Qt Programming
    Replies: 4
    Last Post: 29th April 2012, 14:04
  4. Nested tables (different columns at sub levels)
    By lfiedler in forum Qt Programming
    Replies: 0
    Last Post: 18th March 2011, 16:26
  5. Multiple File Data accessing
    By hasnatzaidi in forum Newbie
    Replies: 1
    Last Post: 28th October 2009, 16:34

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.