Results 1 to 2 of 2

Thread: Working with an API: use objects or QMap/QList?

  1. #1
    Join Date
    Jun 2013
    Location
    Dresden - Germany
    Posts
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Working with an API: use objects or QMap/QList?

    Hi,

    I'm not really new to Qt, because I know it from Python. But I'm a bit new to Qt/C++ so maybe my question is more or less a C++ question.
    I'm working on an movie application using the TheMovieDB API and I'm not quite sure, what's the better idea/solution in my case, for example if you call the API to get credits of movie it returns the following JSON (using QJson stuff to parse it):

    Qt Code:
    1. "cast": [
    2. {
    3. "id": 819,
    4. "name": "Edward Norton",
    5. "character": "The Narrator",
    6. "order": 0,
    7. "cast_id": 4,
    8. "profile_path": "/588Hrov6wwM9WcU88nJHlw2iufN.jpg"
    9. },
    10. ...
    To copy to clipboard, switch view to plain text mode 

    So it's an array with different persons and the information you want. Now my question is: what is the best way to represent the data in Qt. One option could be to create a short "cast" object with some get/set and attributes to hold the information. Another way could be to use QMap, in a QList. I'm not sure about what is the better/cleaner solution? Also I want to use the data later in QML, which seems to be a bit difficult/needs more work, to get the data extracted and QML compatible. At the moment I use for that QMap(QString, QVariant) which can be used easy in QML.

    Some help would be nice!

    Thanks in advance.

    AlphaX2

  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: Working with an API: use objects or QMap/QList?

    If you only need it in the QML based UI it is probably indeed easier to just stick with the QVariantMap.

    Otherwise you'll need to create a model, etc.

    Cheers,
    _

Similar Threads

  1. pointer to nested QMap and QList
    By franki in forum Qt Programming
    Replies: 1
    Last Post: 4th December 2013, 11:44
  2. QMap in QList | i can get value but i can`t set value
    By petrusPL in forum Qt Programming
    Replies: 4
    Last Post: 20th March 2013, 18:40
  3. QMap QList
    By dare5421 in forum Qt Programming
    Replies: 1
    Last Post: 23rd March 2011, 23:17
  4. Replies: 0
    Last Post: 25th June 2009, 08:17
  5. QMap in QList ?
    By npc in forum Newbie
    Replies: 2
    Last Post: 5th February 2007, 11:51

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.