Results 1 to 4 of 4

Thread: converting list to JSON - performance issue.

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

    Default converting list to JSON - performance issue.

    Hi,

    I want to pass the PortalSearchItems list to be passed from qml to Cpp. Eventhough, I can get the result, app got just killed, when this code executes. I assume performance issue.

    Code Snippet: main.qml
    --------------------------------------
    Qt Code:
    1. var varidPortalSearchItemsCount = idPortalSearchItems.totalResults;
    2.  
    3. var vartextJson = "";
    4.  
    5. for (var ii = 0; ii <= varidPortalSearchItemsCount -1 ;ii++)
    6. {
    7. vartextJson += '{"title":"'+ idPortalSearchItems.results[ii].title +'"
    8. ,"owner":"'+ idPortalSearchItems.results[ii].owner +'"
    9. ,"url":"'+ idPortalSearchItems.results[ii].url +'"
    10. ,"itemId":"'+ idPortalSearchItems.results[ii].itemId +'"
    11. }' + ',';
    12. }
    13.  
    14.  
    15. vartextJson = vartextJson.substring(0, vartextJson.length-1) + ']';
    16. vartextJson = '[' + vartextJson;
    17. var varJsonString =JSON.parse(vartextJson);
    18. objHomeController.eveWriteXML(varJsonString);
    To copy to clipboard, switch view to plain text mode 

    HomeController.h
    --------------------------
    Qt Code:
    1. Q_INVOKABLE bool eveWriteXML(const QJsonObject &pqvarPortalItemResult);
    To copy to clipboard, switch view to plain text mode 

    HomeController.cpp
    --------------------------
    Qt Code:
    1. bool HomeController::eveWriteXML(const QJsonObject &pqvarPortalItemResult)
    2. {
    3.  
    4. QVariantMap jsonQVariantMap = pqvarPortalItemResult.toVariantMap();
    5.  
    6.  
    7.  
    8. for(QVariantMap::const_iterator iter = jsonQVariantMap.begin(); iter != jsonQVariantMap.end(); ++iter) {
    9.  
    10. QVariant objQVariant = iter.key();
    11. QVariant objQVariant1 = iter.value();
    12.  
    13. QString strTitleValue = objQVariant1.toMap().values("title").value(0).toString();
    14. QString strUrlValue = objQVariant1.toMap().values("url").value(0).toString();
    15. QString strOwnerValue = objQVariant1.toMap().values("owner").value(0).toString();
    16. QString strItemIdValue = objQVariant1.toMap().values("itemId").value(0).toString();
    17.  
    18. }
    To copy to clipboard, switch view to plain text mode 
    Thanks In advance.
    Last edited by anda_skoa; 29th September 2016 at 11:02. Reason: missing [code] tags

  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: converting list to JSON - performance issue.

    A lot of processing in QML but your choice to do that.

    One thing you could avoid in the C++ code it to convert objQVariant1 into a map several times.
    And calling just value(key) instead of values(key).value(0)

    Also "I assume performance issue" is a no-go. Never assume, always measure.

    Cheers,
    _

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

    Default Re: converting list to JSON - performance issue.

    Hi,

    for(QVariantMap::const_iterator iter = jsonQVariantMap.begin(); iter != jsonQVariantMap.end(); ++iter) {

    QVariant objQVariant = iter.key();//Gives the value of Iteration - 0,1....

    calling just value(key)

    Some code snippet Please.

  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: converting list to JSON - performance issue.

    Quote Originally Posted by Mathan View Post
    QVariant objQVariant = iter.key();//Gives the value of Iteration - 0,1....
    No, gives the key of the iteration.
    Actually a QString.

    Quote Originally Posted by Mathan View Post
    calling just value(key)

    Some code snippet Please.
    Really? You need a code snippet for a single method call on an object?
    Qt Code:
    1. map.value("title");
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

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

    Mathan (1st October 2016)

Similar Threads

  1. Parsing a JSon webservice reply issue
    By roseicollis in forum Qt Programming
    Replies: 12
    Last Post: 11th February 2015, 09:42
  2. Replies: 0
    Last Post: 30th September 2013, 20:47
  3. Performance issue
    By Skorpien126 in forum Qt Programming
    Replies: 4
    Last Post: 2nd July 2010, 17:02
  4. Replies: 0
    Last Post: 16th May 2010, 18:53
  5. Performance Issue
    By linuxdev in forum Qt Programming
    Replies: 1
    Last Post: 10th December 2008, 16: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.