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. Adding QJsonObject to QJsonDocument takes a lot of time
Qt 6.11 is out! See what's new in the release blog

Adding QJsonObject to QJsonDocument takes a lot of time

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 498 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
    MrHandSOme
    wrote on last edited by aha_1980
    #1
    QJsonObject rootObj;
    rootObj["a1"]=a1obj;
    rootObj["a2"]=a2obj;
    rootObj["a3"]=a3obj;
    rootObj["a4"]=a4obj;
    rootObj["a5"]=a5obj;
    
    QJsonDocument newDocument(rootObj);
    

    This part of my code creates a lot of delay in the application. It takes approximately 100 ms. How do I speed this up?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What are all these objects ?
      How did you measure the time ?
      Are you using a debug build ?
      On which OS are you seeing that ?
      Which version of Qt are you using ?

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

      M 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        What are all these objects ?
        How did you measure the time ?
        Are you using a debug build ?
        On which OS are you seeing that ?
        Which version of Qt are you using ?

        M Offline
        M Offline
        MrHandSOme
        wrote on last edited by
        #3

        @SGaist
        All objects are QString.
        I calculate by putting qtime in the upper and lower parts. Even if I don't do this, it creates a slowness in the interface anyway.
        No i am using release build.
        Windows 10.
        6.6.0.
        Thank you.

        Paul ColbyP 1 Reply Last reply
        0
        • M MrHandSOme

          @SGaist
          All objects are QString.
          I calculate by putting qtime in the upper and lower parts. Even if I don't do this, it creates a slowness in the interface anyway.
          No i am using release build.
          Windows 10.
          6.6.0.
          Thank you.

          Paul ColbyP Offline
          Paul ColbyP Offline
          Paul Colby
          wrote on last edited by Paul Colby
          #4

          Hi @MrHandSOme,

          I calculate by putting qtime in the upper and lower parts.

          QTime has some overhead (probably very little, but still...). For interest, try this:

              const quint64 start = QDateTime::currentMSecsSinceEpoch();
              QJsonObject rootObj; qDebug() << (QDateTime::currentMSecsSinceEpoch()-start) << "rootObj";
              rootObj[QStringLiteral("a1")]=QStringLiteral("a1obj"); qDebug() << (QDateTime::currentMSecsSinceEpoch()-start) << "a1obj";
              rootObj[QStringLiteral("a2")]=QStringLiteral("a2obj"); qDebug() << (QDateTime::currentMSecsSinceEpoch()-start) << "a2obj";
              rootObj[QStringLiteral("a3")]=QStringLiteral("a3obj"); qDebug() << (QDateTime::currentMSecsSinceEpoch()-start) << "a3obj";
              rootObj[QStringLiteral("a4")]=QStringLiteral("a4obj"); qDebug() << (QDateTime::currentMSecsSinceEpoch()-start) << "a4obj";
              rootObj[QStringLiteral("a5")]=QStringLiteral("a5obj"); qDebug() << (QDateTime::currentMSecsSinceEpoch()-start) << "a5obj";
              QJsonDocument newDocument(rootObj); qDebug() << (QDateTime::currentMSecsSinceEpoch()-start) << "newDocument";
          

          For me (on Linux though, I don't have Windows handy just at the moment), it shows all of that code executing within a single millisecond, as expected. My output:

          0 rootObj
          1 a1obj
          1 a2obj
          1 a3obj
          1 a4obj
          1 a5obj
          1 newDocument
          

          If that code is slow for you, show us the output. If it's not slow, then try replacing the various QStringLiteral()'s with your versions one at a time and see if that reveals anything.

          Cheers.

          1 Reply Last reply
          2

          • Login

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