Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Converting a list/array to JSON - performance issue.
Forum Updated to NodeBB v4.3 + New Features

Converting a list/array to JSON - performance issue.

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 1.1k Views 2 Watching
  • 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.
  • M Offline
    M Offline
    Mathan M
    wrote on 28 Sept 2016, 16:20 last edited by kshegunov
    #1

    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

    var varidPortalSearchItemsCount = idPortalSearchItems.totalResults;
    
    var vartextJson = "";
    
    for (var ii = 0; ii <= varidPortalSearchItemsCount -1 ;ii++)
    {
    vartextJson += '{"title":"'+ idPortalSearchItems.results[ii].title +'"
    ,"owner":"'+ idPortalSearchItems.results[ii].owner +'"
    ,"url":"'+ idPortalSearchItems.results[ii].url +'"
    ,"itemId":"'+ idPortalSearchItems.results[ii].itemId +'"
    }' + ',';
    }
    
    
    vartextJson = vartextJson.substring(0, vartextJson.length-1) + ']';
    vartextJson = '[' + vartextJson;
    var varJsonString =JSON.parse(vartextJson);
    objHomeController.eveWriteXML(varJsonString);
    

    HomeController.h

    Q_INVOKABLE bool eveWriteXML(const QJsonObject &pqvarPortalItemResult);
    

    HomeController.cpp

    bool HomeController::eveWriteXML(const QJsonObject &pqvarPortalItemResult)
    {
    
    QVariantMap jsonQVariantMap = pqvarPortalItemResult.toVariantMap();
    
    
    
    for(QVariantMap::const_iterator iter = jsonQVariantMap.begin(); iter != jsonQVariantMap.end(); ++iter) {
    
    QVariant objQVariant = iter.key();
    QVariant objQVariant1 = iter.value();
    
    QString strTitleValue = objQVariant1.toMap().values("title").value(0).toSt ring();
    QString strUrlValue = objQVariant1.toMap().values("url").value(0).toStri ng();
    QString strOwnerValue = objQVariant1.toMap().values("owner").value(0).toSt ring();
    QString strItemIdValue = objQVariant1.toMap().values("itemId").value(0).toS tring();
    
    }
    

    Thanks In advance.

    1 Reply Last reply
    0
    • P Offline
      P Offline
      p3c0
      Moderators
      wrote on 29 Sept 2016, 05:26 last edited by
      #3

      @Mathan-M
      Not sure about the performance issues but the way you are trying to extract JSON values seems to be wrong. iter.value() is going to return a QVariant of QString's because
      idPortalSearchItems.results[ii].title, idPortalSearchItems.results[ii].owner ... are all strings.
      So it should be replaced as:

      QVariant v = iter.value();
      QString strTitleValue = v.toString();
      ...
      

      157

      1 Reply Last reply
      3
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 28 Sept 2016, 20:35 last edited by
        #2

        Hi,

        What does a run through the debugger tell you ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • P Offline
          P Offline
          p3c0
          Moderators
          wrote on 29 Sept 2016, 05:26 last edited by
          #3

          @Mathan-M
          Not sure about the performance issues but the way you are trying to extract JSON values seems to be wrong. iter.value() is going to return a QVariant of QString's because
          idPortalSearchItems.results[ii].title, idPortalSearchItems.results[ii].owner ... are all strings.
          So it should be replaced as:

          QVariant v = iter.value();
          QString strTitleValue = v.toString();
          ...
          

          157

          1 Reply Last reply
          3
          • M Offline
            M Offline
            Mathan M
            wrote on 29 Sept 2016, 14:31 last edited by
            #4

            Re: Converting a list/array to JSON - performance issue.

            Hi p3c0,

            Thanks for Help.

            Mathan

            1 Reply Last reply
            0

            1/4

            28 Sept 2016, 16:20

            • Login

            • Login or register to search.
            1 out of 4
            • First post
              1/4
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved