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 QByteArray to QString received from HTTPResponse

Converting QByteArray to QString received from HTTPResponse

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 261 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.
  • U Offline
    U Offline
    Uday More
    wrote on last edited by
    #1

    Hello,
    I am accessing an URL which gives me JSON content as below(Printed using qdebug) : This reply is got from QNetworkReply::readAll function

    {"message": "Success", "code": 200, "scene_label": {"Sequence": [{"SequenceDetails": {"FileName": "abc.h5", "FolderName": ""}, "Labels": [{"SourceType": "Image", "Devices": [{"Channels": [{"ChannelName": "LRR", "SceneLabels": {"GEN_LIGHT_CONDITIONS": [{"starttimestamp": "1558978895055520", "endtimestamp": "1558979211464202", "value": "Dawn"}], "GEN_COUNTRY": [{"starttimestamp": "1558978895055520", "endtimestamp": "1558979211464202", "value": "INDIA"}]}}], "DeviceName": "abc"}]}]}]}}

    But when I try to put in QString to write in file, the string is empty.

    Now again I tried to put in the file directly the bytes, still the same result.
    I suspect there are escape characters which may cause an issue.

    Please guide.

    Thanks.

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

      Hi,

      Are you calling readAll several times ?

      If so, that's your issue. You're at the end of your IO device. The correct thing to do is to store the result of readAll in a variable and then use that one in your code.

      Note that if you want to write to a file, you don't even need to pass by QString. Just write the QByteArray directly.

      If not, then please show the code you are currently using.

      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
      4
      • U Offline
        U Offline
        Uday More
        wrote on last edited by Uday More
        #3

        Hi @SGaist .
        Thanks for the eye opener. Such a silly mistake.
        I called readAll() twice. 1st for printing and then again for storing into variable. So the second fetch is always empty.

        1 Reply Last reply
        0

        • Login

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